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

Add field! for property! #181

Merged
merged 2 commits into from
Apr 22, 2018
Merged

Add field! for property! #181

merged 2 commits into from
Apr 22, 2018

Conversation

c910335
Copy link
Contributor

@c910335 c910335 commented Apr 11, 2018

relate: #57, #120, #144, #171

This PR supports the two syntaxes in #171 by #57.

For example:

class Foo < Granite::ORM::Base
  # ...
  field number : Int32
end

foo = Foo.new(number: 0)
foo.number += 1

This gives:

Error in src/test.cr:7: undefined method '+' for Nil (compile-time type is (Int32 | Nil))

foo.number += 1
^

Rerun with --error-trace to show a complete error trace.

It is still annoying to use foo.number = foo.number! + 1.

With this PR:

class Foo < Granite::ORM::Base
  # ...
  field! number : Int32
end

foo = Foo.new(number: 0)
foo.number += 1 # It works!

This PR also includes the change from type to options in #120 because it is easier to implement field! with this feature.
This PR also removes the property in table.cr because it is duplicated.

Copy link
Contributor

@eliasjpr eliasjpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

faustinoaq
faustinoaq previously approved these changes Apr 19, 2018
@faustinoaq faustinoaq dismissed their stale review April 19, 2018 15:51

Should we add specs for this?

@c910335
Copy link
Contributor Author

c910335 commented Apr 22, 2018

@faustinoaq
Specs were done. 😄

Copy link
Contributor

@faustinoaq faustinoaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@drujensen drujensen merged commit 40f4a09 into amberframework:master Apr 22, 2018
@c910335 c910335 mentioned this pull request Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants