【发布时间】:2013-07-26 14:55:16
【问题描述】:
使用 rails 4.0.0 我试图了解我应该使用什么“多对多、多对一、一对多等”关系来执行以下操作:
Image Table:
|file_name|description|
test.png test image
test2.jpg another test image
Tag table:
|tag_name|
funny
creative
cute
awesome
image_tag table:
|image_id|tag_id|
1, 1
1, 2
1, 3
2, 2
2, 4
etc..
我应该使用什么类型的关系? 这是我正在考虑使用的:
class Image < ActiveRecord::Base
has_and_belongs_to_many :image_tag
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :image
end
【问题讨论】:
-
请正确格式化您的代码
标签: ruby-on-rails rails-activerecord database-relations