-
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
Fields are now required in default. Use foo?
for nilable fields.
#144
Conversation
@maiha nice solution. Thanks for submitting it. I was wondering, should we allow for nilable declaration in the mapping itself?
wdyt? |
Yep. Although there are various preferences, I think that it is better for the API to be consistent in each layers. That is,
Otherwise, we must check its declaration every time we wonder whether it should be |
This appears to be a pretty serious breaking change. Not anytime a user were to try to print or use |
@elorest What about just documenting it?, I mean, we already have been using this change on amber v0.6.5 and v0.6.7, and no amber developer was complaining about this 😅 |
We need to discuss this with @drujensen. My team is still using 0.6.4 and I don't think anyone has really tested the latest versions. |
@elorest I agree that this is a bigger breaking change than I anticipated. I didn't grasp the impact when I merged it. I tried using 0.9.0 with amber cli and it will require changing all the fields in the forms and find methods to use I do like the convenience of not requiring |
I very rarely have to use |
@maiha should we roll this change back? |
I think it’s worth pulling back this feature. The right way may be to rollback this commit or not but this level of breakage is not something that should be done without major buy in across the amber ecosystem. I’m with @elorest on this, it’s uncommon that I’ve ever had to use .not_nil! To resolve this. An alternate crystal prescedent exists to strip the nil away and is more alike the rails style which is to add an exclamation to the getter which will throw: |
Would be nice to read @maiha comments/opinions/suggestion about this 😅 |
I believe that this specification makes most users happy as I commented in https://github.com/amberframework/granite-orm/pull/146#issuecomment-377668234 current behavior# for users who desires the field should not be nil
cat.name # simple!
# for users who desires the field would be nil
cat.name? || "your cat doesn't have a name" Otherwise, the former users will be forced ugly and unnecessary not_nil! hell as it was in previous versions. previous behavior# for users who desires the field should not be nil
cat.name.not_nil! # why I must check nilable in spite of DB has not null constraint.
id = User.create.id.not_nil! # why I must check primary key exists
# for users who desires the field would be nil
cat.name || "your cat doesn't have a name" This old behavior make the former users always unhappy.
But, of course, if the community determines that the previous behavior is desirable, we should revert these commits or rollback to 0.8.4. In that case, I use my fork so there is no problem at all. |
@maiha Thank you for your comment! What about this: # for users who desires the field should not be nil
cat.name! # notice the admiration symbol
# for users who desires the field would be nil
cat.name || "your cat doesn't have a name" |
@faustinoaq I like this proposal. This avoids the breaking change. I think we can accomplish this by renaming the methods. @maiha does this work for you? We would hate to see you use your branch and we definitely hate unhappy developers. Right now, I'm unhappy because this change breaks Amber in more ways than I originally envisioned. We can't integrate v0.9.0 in the templates because other ORM's do not support this approach. |
@drujensen I am sorry for interfering with cooperation between v0.9 and Amber. Is it difficult for Amber to prepare different generator templates for each ORMs? If it's not easy, let's revert this commit ASAP! |
…elds. (amberframework#144)" This reverts commit c9cfc3d.
@maiha No, we are not going backwards. Check this out! https://github.com/amberframework/granite-orm/pull/171 |
In this PR, field requires values by default, otherwise raises the proper missing exceptions.
Now, users can avoid the redundant
not_nil!
, and also can usefoo?
for the nilable cases.Best regards,