Hi, I have a one-to-many relationship. I want to be able to add objects to the collection w/out persisting them. How do I do this? The only thing I can''t think of is to use a transaction and roll it back. In other words - I want to do this: o = Order.find(1) p = Product.find(1) o.products << p # but don''t persist this I assume I''m just missing something obvious here. Any ideas? Thanks, Ben
Hm, maybe clone/dup the object? On 3/8/06, Ben Anderson <benanderson.us@gmail.com> wrote:> Hi, > I have a one-to-many relationship. I want to be able to add objects > to the collection w/out persisting them. How do I do this? > > The only thing I can''t think of is to use a transaction and roll it back. > > In other words - I want to do this: > > o = Order.find(1) > p = Product.find(1) > o.products << p # but don''t persist this > > I assume I''m just missing something obvious here. Any ideas? > Thanks, > Ben > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Mark Reginald James
2006-Mar-08 23:13 UTC
[Rails] Re: order.products << product w/out persisting
Ben Anderson wrote:> I have a one-to-many relationship. I want to be able to add objects > to the collection w/out persisting them. How do I do this? > > The only thing I can''t think of is to use a transaction and roll it back. > > In other words - I want to do this: > > o = Order.find(1) > p = Product.find(1) > o.products << p # but don''t persist thiso.products.to_ary << p -- We develop, watch us RoR, in numbers too big to ignore.
yes, but I still want it to be there as an unpersisted member, so I get it when I do o.products.each do |p| ... end On 3/8/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> Ben Anderson wrote: > > > I have a one-to-many relationship. I want to be able to add objects > > to the collection w/out persisting them. How do I do this? > > > > The only thing I can''t think of is to use a transaction and roll it back. > > > > In other words - I want to do this: > > > > o = Order.find(1) > > p = Product.find(1) > > o.products << p # but don''t persist this > > o.products.to_ary << p > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Mark Reginald James
2006-Mar-09 01:32 UTC
[Rails] Re: order.products << product w/out persisting
Ben Anderson wrote:> yes, but I still want it to be there as an unpersisted member, so I > get it when I do > > o.products.each do |p| > ... > end > > On 3/8/06, Mark Reginald James <mrj@bigpond.net.au> wrote: >>o.products.to_ary << pHmm, I''m surprised this doesn''t work. -- We develop, watch us RoR, in numbers too big to ignore.