2010/4/27 Jeremy Evans <[email protected]>:
> The nested_attributes plugin should work for what you are doing.
I took a look, and, unfortunately, I don't think it will be enough.
I didn't how to add nested attributes to an already instancied model.
And unless I'm mistaken, the unsaved model will not retrieve real rows.
> If
> not, note that you can manually manipulate the association cache for
> each model object using the associations method:
>
> post.associations[:comments] = Author.new(...)
> post.associations[:comments] = [Comment.new(...), Comment.new(...)]
I'm not sure, but it will not link to existing rows until I save ?
Like, if I had author also for comments, and I want to do something like this :
class Post
def comments_authors
self.comments.collect do |comment|
comment.author
end
end
end
post.new(...)
post.associations[:comments] = [Comment.new(:author_id =>
Author.first(:name => 'foo'))]
post.comments_authors.each do |author|
puts author.name
end
> You may need to do this instead of using the association methods
> themselves if you want to use objects that aren't in the database and
> don't want any modifications to the database.
I would like modifications to take effect only when the user click
'save'. Otherwise forget about it. I think I will go as I was
initially, with a pseudo model while it's not saved, and then create
it in the database when user saves.
regards
Simon
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.