I have two database tables
An account must have an owner_id which is a user's id. So the owner_id
field must not be null. A user must have an account_id and so
account_id must not be null also. I create the account first but then
the owner_id has to be null at least until the user is created and I
know the user's id. This is a problem like the chicken and the egg.
I searched google but wasn't able to find how to handle this problem
in a Rails app.
One approach is I can allow owner_id to be null and when creating the
account I can create the account, create the user with the account_id,
and then set the owner_id on the account. Then check that all went
well. This whole dance happens in the Ruby of my Account model. This
doesn't seem like fully safe approach. Is there something better?
I'm using PostgreSQL but am hoping there is a database agnostic solution.