Thanks Alex, you’re a true rails genius.
I’ve done this like you said. This is your second method:
But it tries to insert the previous primary key into the table,
therefore violating the PK constraint. I have to use a custom primary
key named “branch_id”. Any ideas?
Alex Y. wrote:
There are a few ways you could do this. The first would be to override
the new_record? method to always return true, so that when save() gets
called, it always thinks it needs to create() rather than update(). The
second would be to set the value of @new_record to true in a before_save
callback. A third would be to override the save() method to call
create() rather than create_or_update(). A fourth would be to override
create_or_update() to always call create(), and never update().
All of these should preserve validations.
So many choices, so little time