Makes sense, will do that. Just wanted to check if maybe I was missing something...
On Thursday, March 2, 2017 at 2:35:28 AM UTC+2, Jeremy Evans wrote: > > On Wednesday, March 1, 2017 at 3:50:07 PM UTC-8, Aryk Grosz wrote: >> >> Whenever I use this plugin, if I'm trying to check based on the primary >> key, I get an error because it always tries to set the foreign key >> attribute on the resulting record (whether it's being created or updated). >> > > Trying to check based on the primary key with update_or_create doesn't > make sense unless you are unrestricting access to the primary key. If you > do: > > update_or_create(:id=>1, :name=>'Foo') > > It's going to look for a record with (id = 1 AND name = 'Foo'), and if it > does not find one, it's going to insert a record with (id = 1, name = 'Foo') > > It sounds like you want to try to find a record with a given primary key, > update the record matching the primary key with the given attributes if it > doesn't exist, and create a new record with a different primary key if it > doesn't exist. That's not what update_or_create is designed to do. > > >> Was this intentional behavior? If you have incoming attrs and want to >> check for the primary key and pull the record based on that, does it have >> to be done manually? Or is there something in the library that I'm missing? >> > > The current behavior is intentional. For your needs, I would recommend > using the custom method you posted instead. > > 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 post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
