Ruby on Rails
Thursday, February 1, 2018
On Thursday, February 1, 2018 at 11:16:29 AM UTC-5, Hassan Schroeder wrote:
On Wed, Jan 31, 2018 at 11:30 PM, fugee ohu <fuge...@gmail.com> wrote:
> I'm having find_or_create_by roll back on me in the console directly from
> the model I'm not providing an id, the mysql id column is autoincrement
> Model.find_or_create_by(person_id: 1, picture_id:37)
Aside from what other people have already pointed out --
Model.find_or_create_by! will raise an exception on failure, which
will give you more direct info.
I highly recommend reading the docs.
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Thanks Hassan, yes that was very revealing PIcture must exist, Car must exist, Address must exist ... seems like everything in the belongs_to list has to exist? I think I need to do this in a more conventional way than to use the unrelationed find_or_create_by
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/365d0ac1-005a-4cbc-ad34-ebd7bc8e4891%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment