Lille
2010-Nov-30 20:13 UTC
how to ''delete'' an object from an association collection in-memory only
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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pepe
2010-Dec-01 01:55 UTC
Re: how to ''delete'' an object from an association collection in-memory only
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-01 05:21 UTC
Re: how to ''delete'' an object from an association collection in-memory only
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, > > LilleBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Simon
2010-Dec-01 08:23 UTC
Re: how to ''delete'' an object from an association collection in-memory only
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- Rails and Service Oriented Architecture (SOA): any downsides?
- what is a session stored via the active_record_store option unique to?
- jQueryUI autocomplete (Rails 3.1): can't get source as url to work
- Unknown column 'quotes.organisation_id' in 'where clause': SELECT * FROM `quotes` WHERE (`quotes`.organisation_id = 1036)
- Deep nested associations on the same Model