I have a simple has_one / belongs to the relationship between the two models.
This is a new association in my application, so there are many records that have not yet created a related record.
In my application, I assume that the model has an association, and I get access to its attributes and methods. However, since the association does not exist, I encounter many errors.
What I would like to do is to unobtrusively create a linked record on the fly whenever she first gets access to any of her methods and attributes. It doesn't matter what the data is in the record, I just need it to exist, so the methods that I call can create the data.
Edit: I don’t want to check and create a record in all instances where I try to access relationships, so this is an ideal solution for the model itself, and not in my controllers anywhere.
Any thoughts?
Thanks!
source
share