The model reference in add_belongs_to can lead to issues #709
Labels
clarify api
Rename/remove/add something to make the API easier to understand
needs investigation
A possible bug / better docs needed. Investigate further
Ref: #685 (comment)
Right now, the type used in
add_belongs_to
is only used for generating a table reference name, and not for enforcing a type. If you use a model that's in a namespace, you won't get the reference that you're expecting in some cases.Take this for example:
This will create the
user_id
column, but tell postgres that the foreign key references themy_app_users
table. To fix this, you would add thereferences
option:add_belongs_to user : MyApp::User, references: :users, on_delete: :cascade
or don't use a namespaced type here.add_belongs_to user : User, on_delete: :cascade
.We can either make this easier to know (no clue how), or we can look at trying to resolve the model to get its table name...
This might be a tricky one.
The text was updated successfully, but these errors were encountered: