My data resembles this:
class Team < ActiveRecord::Base
has_many :persons
belongs_to :leader, :class_name => "Person"
end
class Person < ActiveRecord::Base
belongs_to :team
end
I create the Team like this:
@team = Team.new
for (each new person as p)
new_person = @team.persons.build
new_person.name = p.name
if p.is_marked_as_leader
@team.leader = new_person
end
end
@team.save
When I list @team.persons, @team.leader has the first id, I guess because @team.save is saving the leader association before persons. I need them to be in the order they are provided, where the :leader belongs_to references one of the ID's within my has_many :persons
Thanks!