[Rails] Re: how to 'delete' an object from an association collection in-memory only

2010-12-01 Thread Simon
Hi,

I'm not sure why you are worried about touching the data store.
collection.build doesn't save the new object so there is nothing in
the db that could be deleted.
If all you want to do is revert collection.build just remove that
element of the association array (as pepe pointed out).

comment = @post.comments.build
@post.comments.delete(comment)

or

@post.comments.build
@post.comments.delete(@post.comments.last)

Hope this helps!

Simon

On Nov 30, 9:13 pm, Lille lille.pengu...@gmail.com wrote:
 Hi,

 My Rails app offers opportunities to try out models on a 'what-if'
 basis, where dependent associations can be modified to obtain
 alternative results for the parent. Is there a way to delete/destroy
 the member of a collection so that I can play around with the
 accordingly modified parent in memory, without actually committing the
 destruction of the collection member to the data store? Based on my
 read of the docs, there is no 'delete' counterpart to
 'collection.build' for association members.

 Thanks for any comment,

 Lille

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: how to 'delete' an object from an association collection in-memory only

2010-11-30 Thread pepe
If I understand you correctly you only need to remove the
association's array element. That will not delete the underlying DB
record if there is one.

On Nov 30, 3:13 pm, Lille lille.pengu...@gmail.com wrote:
 Hi,

 My Rails app offers opportunities to try out models on a 'what-if'
 basis, where dependent associations can be modified to obtain
 alternative results for the parent. Is there a way to delete/destroy
 the member of a collection so that I can play around with the
 accordingly modified parent in memory, without actually committing the
 destruction of the collection member to the data store? Based on my
 read of the docs, there is no 'delete' counterpart to
 'collection.build' for association members.

 Thanks for any comment,

 Lille

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: how to 'delete' an object from an association collection in-memory only

2010-11-30 Thread Marnen Laibow-Koser
Lille wrote in post #965224:
 Hi,

 My Rails app offers opportunities to try out models on a 'what-if'
 basis, where dependent associations can be modified to obtain
 alternative results for the parent. Is there a way to delete/destroy
 the member of a collection so that I can play around with the
 accordingly modified parent in memory, without actually committing the
 destruction of the collection member to the data store? Based on my
 read of the docs, there is no 'delete' counterpart to
 'collection.build' for association members.

If it were my app, I think I'd do this differently: start a transaction 
for the what if stuff, then either roll it back or commit it when 
done.


 Thanks for any comment,

 Lille

Best,

-- 
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Sent from my iPhone

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.