On Mon, Aug 30, 2021 at 12:19 PM Rob Galanakis <[email protected]> wrote:

> Thanks, that is some useful code!
> For this case though, it doesn't fulfill the need- the original models in
> `a` are replaced with new references. For example, this situation would
> need to pass:
>
> x = T.new(name: 'A')
> a = [x]
> bulk_create_ala_jeremy(a)
> assert x.id > 0
> assert !x.new?
>
> Admittedly, this does seem rather obscure- in this case, I have a series
> of what are basically paired models; I want to do something like this:
>
> model_a = []
> model_b = []
> (0..5).each do |i|
>   model_a << A.new
>   model_b << B.new
> end
> bulk_create(model_b)
> model_a.zip(model_b).each { |a, b| a[:b_id] = b.id }
> bulk_create(model_a)
>

For this type of thing, it sounds like you would want to use the
nested_attributes plugin, so you could automatically create and associate
the appropriate model_b when saving model_a.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSdZOXQR6T6w33OZauNjoKVTY40t0Y1dqdEWFa5jGmQpbg%40mail.gmail.com.

Reply via email to