ActiveRecord has_many where two columns in table A are primary keys in table B?

The relationships declared in Couple should look like this: class Couple named_scope :with_people, { :include => :first_person, :second_person } belongs_to :first_person, :class_name => 'Person' belongs_to :second_person, :class_name => 'Person' end #usage: Couple. With_people. First # => , @second_person: 'first_person_id', :class_name => 'Couple' has_one :couple_as_second_person, :foreign_key => 'second_person_id', :class_name => 'Couple' def couple couple_as_first_person || couple_as_second_person end end If a Person can belong to several Couple s, and there's no way to tell whether they're the "first" or "second" in any given Couple you might want: class Person has_many :couples_as_first_person, :foreign_key => 'first_person_id', :class_name => 'Couple' has_many :couples_as_second_person, :foreign_key => 'second_person_id', :class_name => 'Couple' def couples couples_as_first_person + couples_as_second_person end end.

The relationships declared in Couple should look like this: class Couple named_scope :with_people, { :include => :first_person, :second_person } belongs_to :first_person, :class_name => 'Person' belongs_to :second_person, :class_name => 'Person' end #usage: Couple. With_people. First # => , @second_person: > Those in Person depend on whether a Person can be part of more than one Couple.

If a Person can only belong to one Couple and can't be the "first" Person on one and the Second on another, you might want: class Person has_one :couple_as_first_person, :foreign_key => 'first_person_id', :class_name => 'Couple' has_one :couple_as_second_person, :foreign_key => 'second_person_id', :class_name => 'Couple' def couple couple_as_first_person || couple_as_second_person end end If a Person can belong to several Couples, and there's no way to tell whether they're the "first" or "second" in any given Couple, you might want: class Person has_many :couples_as_first_person, :foreign_key => 'first_person_id', :class_name => 'Couple' has_many :couples_as_second_person, :foreign_key => 'second_person_id', :class_name => 'Couple' def couples couples_as_first_person + couples_as_second_person end end.

This is a well-written, well thought-out answer. Thanks so much. I'll test this soon and let you know.

– user94154 Jan 26 '10 at 1:54 haven't tested it yet, but you WIN :) – user94154 Jan 28 '10 at 20:40.

Untested, but according to the Rails API documentation, maybe something like: class Couple :first_person_id has_one :person, :foreign_key => :second_person_id end.

Those should be belongs_to, not has_one, since the foreign keys are on this model. – floyd Jan 24 '10 at 2:45.

Theory only, untested: Create two subclasses of Person: class FirstPerson :first_person_id has_many :second_persons, :foreign_key => :second_person_id Then find: Couple. All(:include => :first_persons, :second_persons).

C = Category. >> a = Assignment. Create(:post_uuid => p.

Uuid, :category_uuid => c. Category Load (0.0ms) SQLite3::SQLException: no such column: assignments. Uuid: SELECT "categories".

* FROM "categories" INNER JOIN "assignments" ON "categories". Id = "assignments". Uuid WHERE (("assignments".

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: assignments. Uuid: SELECT "categories". * FROM "categories" INNER JOIN "assignments" ON "categories".

Id = "assignments". Uuid WHERE (("assignments".

The relationships declared in Couple should look like this.

Untested, but according to the Rails API documentation, maybe something like.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions