Reputation: 11336
I'm wondering what would be the ideal way to find or create a nested record using something similar to the find_or_crate
method.
For regular attributes there's the very convenient User.find_or_create_by_attribute
method.
Is there anything for a nested association?
Let's say a User
has a Profile
. What would be the ideal way to find or create based on its profile
presence?
Upvotes: 0
Views: 62
Reputation: 8892
I don't think you're going to find anything sexier than profile = user.profile || user.create_profile
.
Upvotes: 1