Skip to content
Snippets Groups Projects
Commit 90201c27 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add collection_items model

parent e71301d7
No related branches found
No related tags found
No related merge requests found
class Collection < ActiveRecord::Base
has_and_belongs_to_many :learning_objects
has_many :collection_items
has_many :collection_items, as: :collectionable
has_many :collections, :through => :collection_items, :source => :collectionable, :source_type => 'Collection'
has_many :learning_objects, :through => :collection_items, :source => :collectionable, :source_type => 'LearningObject'
belongs_to :user
has_many :reviews, as: :reviewable
......@@ -7,4 +12,6 @@ class Collection < ActiveRecord::Base
has_many :downloads, as: :downloadable
has_many :likes, as: :likeable
has_many :shares, as: :shareable
has_many :follows, as: :followable
end
class CollectionItem < ActiveRecord::Base
belongs_to :collection
belongs_to :collectionable, polymorphic: true
end
class Follow < ActiveRecord::Base
belongs_to :followable, polymorphic: true
belongs_to :user
end
class LearningObject < ActiveRecord::Base
has_and_belongs_to_many :subjects
has_and_belongs_to_many :collections
has_many :collection_items, as: :collectionable
has_many :collections, through: :collection_items
has_many :complaints
has_many :reviews, as: :reviewable
......
......@@ -18,6 +18,7 @@ class User < ActiveRecord::Base
has_many :likes
has_many :shares
has_many :follows
has_many :follows, as: :followable
after_create :default_role
......
class CollectionsLearningObjects < ActiveRecord::Migration
def change
create_table :collections_learning_objects do |t|
t.integer :collection_id
t.integer :learning_object_id
t.timestamps null: false
end
end
end
class CreateCollectionItems < ActiveRecord::Migration
def change
create_table :collection_items do |t|
t.references :collectionable, polymorphic: true, index: {name: "index_citems_on_ctype_and_cid"}
t.references :collection, index: true
t.integer :order
t.timestamps null: false
end
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class CollectionItemTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment