0
是否有可能使has_one關係像這樣工作?rails 3.1 - has_one,通過
我希望能夠能夠加載的記錄是這樣的:
@person = Person.find(1) => {Person id: 1, favorite_house_id: 10}
@person.favorite_house => {House id: 10....)
class Person < ActiveRecord::Base
has_many :houses, through: :person_houses
has_one :favorite_house, through: :person_houses
end
class PersonHouse < ActiveRecord::Base
belongs_to :house
belongs_to :person
end
class House < ActiveRecord::Base
has_many :people, through: :person_houses
end