-
Notifications
You must be signed in to change notification settings - Fork 64
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 support for optional arrays #471
Add support for optional arrays #471
Conversation
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.
Good call on this! I think the implementation is definitely much cleaner this way. I'd like to see just 1 more spec for a little extra safety, and then I think we're good 👍
%from_db.as({{column[:type]}}) | ||
{% end %} | ||
def {{column[:name]}} : {{column[:type]}}{{(column[:nilable] ? "?" : "").id}} | ||
{{ db_type }}::Lucky.from_db!(@{{column[: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.
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 think they just use the default from_db!
coming from Avram::Type
https://github.com/luckyframework/avram/blob/master/src/avram/type.cr#L6
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.
ohh... sneaky 😂
@@ -112,18 +112,17 @@ class Avram::Migrator::AlterTableStatement | |||
end | |||
|
|||
macro add(type_declaration, index = false, using = :btree, unique = false, default = nil, fill_existing_with = nil, **type_options) | |||
{% if type_declaration.type.is_a?(Union) %} | |||
{% type = type_declaration.type.types.first %} | |||
{% type = type_declaration.type %} |
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.
Yeah, this is much cleaner!
it "handles optional Array" do | ||
BucketBox.create &.numbers(nil) | ||
bucket = BucketQuery.new.last | ||
bucket.numbers.should be_nil |
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'm pretty sure it works, but just for peace of mind, can you add to this spec where we take this bucket and update it to have an empty array? Or maybe add another spec in here that just tests a SaveOperation can have a nilable array but be updated to an empty array?
Fixes #470
There are a couple of bugs that are fixed by these changes: