Video、a、およびSonganにArticleは多くのがありTagsます。そして、それぞれTagが多くを持つことができますVideo, Songs or Articles。だから私は5つのモデルを持っています:Video, Song, Article, Tag and Taggings。
これらのモデルは次のとおりです。
class Video < ActiveRecord::Base
has_many :tags, :through => :taggings
end
class Song < ActiveRecord::Base
has_many :tags, :through => :taggings
end
class Article < ActiveRecord::Base
has_many :tags, :through => :taggings
end
class Tag < ActiveRecord::Base
has_many :articles
has_many :videos
has_many :songs
belong_to :taggings, :polymorphic => true #is this correct?
end
のデータベース定義Taggings
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Taggingsモデル:
class Taggings < ActiveRecord::Base
belongs_to :tag #is this correct?
belong_to :taggable, :polymorphic => true #is this correct?
end
私が心配している問題は、モデルの正しい定義がありますか(belongs_to、has_many?)?私の腸は私が何かを逃したと私に言います。私はたくさんの記事を見てきました、そして私はそれらにかなり混乱しています。