레일스에서 연관성을 어느 정도로 사용할 수 있는지 궁금합니다. 내가 User.bids
같은 일을하고 약이 멋진 User.businesses
및 Provider.bids
같은 바로 가기하지만를 설정할 수 있어요레일 has_many : through has_many : through
class User < ActiveRecord::Base
has_one :provider
has_many :businesses, :through => :provider
end
class Provider < ActiveRecord::Base
has_many :businesses
has_many :bids, :through => :businesses
belongs_to :user
end
class Business < ActiveRecord::Base
has_many :bids
belongs_to :provider
end
class Bid < ActiveRecord::Base
belongs_to :business
end
: 고려 사항으로 다음을 가지고? 협회를 연상시키는 것이 가능합니까?
데이터베이스와 레일 응용 프로그램을 늪에 빠뜨릴 수 있기 때문에 가능한 한 중첩하는 방법에주의해야합니다. 즉, 나는 이것을하기 위해 nested_has_many_through를 어떻게 사용하는지에 대한 세부적인 블로그 포스트를 작성했다 : http://kconrails.com/2010/01/28/nesting-has_many-through-relationships-in-ruby-on-rails/ –