From 16e9b3a6b78f5327e686900d71cdd01c7d96ae5f Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com> Date: Thu, 15 Oct 2015 10:42:14 -0300 Subject: [PATCH] now, collection can add and remove learning objects --- app/models/collection.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/models/collection.rb b/app/models/collection.rb index d5a481f2..07142afc 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -10,6 +10,31 @@ class Collection super(params.merge(defaults)) end + ## + # Add +learning_object+ to collection + # + # After adding some learning object to collection, you must use CollectionRepository to persist + # the changes. + # + # Example: + # @test_collection = Collection.new(name: 'test', description: 'test', owner: current_user) + # @test_collection.add @learning_object + # + # @test_collection.learning_objects # [@learning_object] + # collection_repository.save @test_collection + def add(learning_object) + learning_objects.append learning_object + end + + ## + # Remove +learning_object+ from collection + # + # After remove some learning object to collection, you must use CollectionRepository to persist + # the changes. + def remove(learning_object) + learning_objects.delete learning_object + end + private def defaults -- GitLab