You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the simple case the primary key is a synthetic id that is auto-generated by the database. In the not so simple case, you have overridden the primary key so that it's not auto-generated by the database. It could be a business key that is meaningful. It could be a one-to-one mapping where the primary key is a foreign key reference to another table.
e.g.
# This has a normal auto-incrementing ID
schema "plays" do
has_one :scoring
end
# This is a one-to-one modeled in the database by having the PK be a FK to the plays.id column.
@primary_key {:play_id, :integer, []}
schema "scoring" do
field :type, :string
field :points, :integer
belongs_to :play, MyApp.Play, define_field: false, references: :id
belongs_to :team, MyApp.Team, references: :id
end
In the latter case, the primary key is also a foreign key reference to another table and is a required field, so using params_for and friends creates invalid params since it drops the PK.
The text was updated successfully, but these errors were encountered:
Found this problem using
params_for
, etc.In the simple case the primary key is a synthetic id that is auto-generated by the database. In the not so simple case, you have overridden the primary key so that it's not auto-generated by the database. It could be a business key that is meaningful. It could be a one-to-one mapping where the primary key is a foreign key reference to another table.
e.g.
In the latter case, the primary key is also a foreign key reference to another table and is a required field, so using
params_for
and friends creates invalid params since it drops the PK.The text was updated successfully, but these errors were encountered: