Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support belongs to with namespaced classes #685

Merged

Conversation

matthewmcgarvey
Copy link
Member

Fixes #684

add_belongs_to namespaced_assoc : Namespaced::Assoc, on_delete: :cascade

Before: namespaced::assocs
After: namespaced_assocs

@jwoertink
Copy link
Member

If you have a custom table set within the namespace, does this account for that?

For example:

module Burns
  class Video < BaseModel
    table :videos do

    end
  end
end

# This should still be video_id, not burns_video_is
add_belongs_to video : Burns::Video

@matthewmcgarvey
Copy link
Member Author

@jwoertink I pointed out in the issue, any reference to a class is completely fake in migrations. There is no connection between the name of the class I put in an add_belongs_to and any class in the models directory. That's why the solution I used to get around the bug was to make that type NamespacedAssoc so it got turned into the correct table name. In order to handle what you defined, you'd have to do:

add_belongs_to video : Video, on_delete: :cascade

@jwoertink
Copy link
Member

Wait, so you can do add_belongs_to thing : SomeModelThatIsNonExistant, and that will work? 🤨 That sounds like a bug, but I guess irrelevant to this PR.

@matthewmcgarvey
Copy link
Member Author

@jwoertink This is why I don't like using table_for and things like that in migrations. It creates a false impression that the migration is connected to the model when it isn't.

@matthewmcgarvey matthewmcgarvey merged commit 6c12136 into luckyframework:master Jun 10, 2021
@matthewmcgarvey matthewmcgarvey deleted the belongs-to-module branch June 10, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't add belongs to in migration with class in a module
2 participants