I have a Bill
model with nested Customer
model.
The Customer
model has a phone number with a uniqueness validation on it.
While creating the bill I want to fetch the existing record based on the phone number or create a new one if such doesn't exist.
How should I do it in a RESTful
way?
you would use the find_or_create_by method which would look something like this in your case:
fetchedRecord = Bill.find_or_create_by_phone_number(customer.phone_number)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With