-
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
Dj/129 has many #278
Dj/129 has many #278
Conversation
I think the syntax is not intuitive. has_many cats, class: Cat |
@c910335 I decided to follow the same syntax used in Let me see if I can rework it. I have very little time so this may have to wait for the weekend. |
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.
I love this the way it is. Type declaration is a consistent crystal pattern, and this feels natural to me. Thanks Dru
src/granite/associations.cr
Outdated
Granite::AssociationCollection(self, {{model.id.camelcase}}).new(self, {{through}}) | ||
end | ||
{% end %} | ||
macro has_many(model, model_name) |
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.
model
is no longer really descriptive here, is it more of the name of the getter?
@robacarp I like the type declaration as well but I agree with @c910335 that Please re-review this as I have removed the type declaration in favor of I have also implemented |
@c910335 I'm thinking of adding back the type declaration |
I added support for both syntax. Let me know what you think. |
ping! |
I'm merging this if there is no feedback. Let me know if we need any changes. |
This PR addresses issue #129 by removing the automatic pluralization (adding
s
) to the table name. I think the industry agrees this is a bad practice. If you want to pluralize the name, you need to specify thetable_name
explicitly.It also changes the
has_many
relation to remove stripping of thes
and add support to allow you to use a type declaration as follows:This eliminates the need for adding a inflector to the macro level. This is a breaking change and moves away from the Rails pluralization. You can still pluralize if you want but you need to explicitly specify the type if you do.
This PR also allows you to specify a custom
foreign_key
:This PR also refactors the
has_one
to use the double splat for options so they can be provided in any order.