Topic: Block object not iterating?
The following block of code is being used to populate data into my rails application db:
def make_group_members
User.all.each do |user|
Group.all.each do |group|
Membership.create do |membership|
membership.member_id = user.id,
membership.group_id = group.id,
membership.status = "pending"
end
end
end
end
I have 10 users and 10 groups. When the file executes, as expected, the table is populated with 100 records. The group_id column has 10 records for each of the 10 groups.
The problem is that the member_id column is populated with the value "1". However, I'm expecting the member_id column to be "1" for the first 10 records, "2" for the next 10 records and so on...
foolishly, I've killed almost 4 hours trying to troubleshoot this today.
Thanks for your help!!!