Association loop

13 views
Skip to first unread message

morgoth

unread,
Feb 16, 2010, 9:27:09 AM2/16/10
to Machinist Users
I have problem with associations:
User has many points
Point belong to user

In blueprints:

User.blueprint do
attributes...
end

Point.blueprint do
user
value
end

Now I want to create named bluprint:
User.blueprint(:with_points) do
points { create points for that user}
end

How to pass user object to points?
Something like:

points { [Point.make(:user => self)] }

Pete Yandell

unread,
Feb 17, 2010, 8:10:27 PM2/17/10
to Machinist Users
I strongly suggest just making a separate helper:

def make_user_with_points
user = User.make
3.times { user.points.make }
user
end

If you try to do it in the blueprint, ActiveRecord will try to save
the user so it can construct the points, but of course you haven't
finished constructing the user yet...

Machinist is good at attribute values, but it's not good at object
graphs.

- Pete

Reply all
Reply to author
Forward
0 new messages