I have this schema:

- There is a table for persons.
- Each person has one “info” table.
- Persons can have friends. This is stored in another table called “friends”, which has a foreign key for the person, and another one for his friend (both are pointing to the “person” table).
“person” model:
class Person < ActiveRecord::Base
has_one :info
has_many :friends
end
“info” model:
class Info < ActiveRecord::Base
belongs_to :person
attr_accessible :description
end
“friends” model:
class Friend < ActiveRecord::Base
belongs_to :person
attr_accessible :friend_id
end
Let’s suppose we have 2 persons: person1 and person2. Each one with a record in the “info” table storing its description. And let’s suppose that person2 is a friend of person1.
content of “person” table:
id: 1
id: 2
content of “info” table:
id: 1, person_id: 1, description: “This is person 1, our main dude.”
id: 2, person_id: 2, description: “This is person 2, our secondary dude.”
content of “friends” table:
id: 1, person_id: 1, friend_id: 2
If I want to get person1’s friends I do this:
Person.first.friends
This will give me:
id: 1, person_id: 1, friend_id: 2
Now, how do I add the “info” content for each row?
Here is the first solution I have come with:
Anyone with a better/clearer/more efficient one?