【发布时间】:2018-06-14 01:10:04
【问题描述】:
尝试创建一个域,用户可以在其中创建咖啡和混合咖啡列表。一种混合物有许多咖啡,一种咖啡有许多混合物。这是我目前所拥有的:
class User < ActiveRecord::Base
has_many :roasts
has_many :blends, :through => :roasts
class Roast < ActiveRecord::Base
belongs_to :user
# TODO: associate roasts with blends
class Blend < ActiveRecord::Base
# TODO: associate blends with roasts
我如何建立这种关系?我需要某种连接表吗?
【问题讨论】:
标签: ruby activerecord model-associations