-
Notifications
You must be signed in to change notification settings - Fork 88
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 custom method name #186
Support belongs_to custom method name #186
Conversation
src/granite_orm/associations.cr
Outdated
end | ||
|
||
macro belongs_to(model_name, decl) | ||
# ditto | ||
macro belongs_to(model, decl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like decl
is a pattern that is already used in this file, but what does it stand for? It seems like it means foreign_key
? Can we call it something more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment, but I like this improvement and could make use of it immediately. Thanks!
@robacarp belongs_to author : User, foreign_key: author_id : String And I think this syntax should be recommended. |
@robacarp Is it possible to use
Can someone direct me to the actual documentation for its usage? Also, I guess part of the confusion is that there exists |
@conradwt You should be using |
Example:
Or both this feature and custom id in #142
This is very useful because
article.author
is much more readable thanarticle.user
, and an article may need to belong to more than one kind of user, for example, author and approver.