Rails: Attempting Save An Existiing Row But Rails Generates Sql Insert Instead Of Update
The error When I have a new record, I don't have a problem. When I have an existing record I'm trying to update, an exception (see below) is thrown. The following two variants of R
Solution 1:
Since you are using a non standard id, you need to tell rails the column to use as a primary_key, this way it can evaluate whether a save should insert or update.
To do so you need to add self.primary_key = 'email_address_id' in your model.
Remember Rails favors convention over configuration, so anytime you break convention you need to tell Rails.
P.S.: it seems redundant having the pkey for email_addresses named email_address_id; usually the format of resource_id is conventionally used for fkeys, while for pkeys you can just define the column name.
Post a Comment for "Rails: Attempting Save An Existiing Row But Rails Generates Sql Insert Instead Of Update"