Closed foobear closed 2 years ago
Consider the following model.
class Post < ApplicationRecord belongs_to :user, optional: true end
Now consider a form model which resolves a post's user only to visible users.
user
class Frontend::Post < ActiveType::Record[::Post] change_association :user, -> { visible } end
The above will not work, and instead result in an error:
lib/active_type/change_association.rb:18:in `merge': no implicit conversion of nil into Hash (TypeError)
Instead, passing an (empty) options hash is required to make it work:
class Frontend::Post < ActiveType::Record[::Post] change_association :user, -> { visible }, {} end
I assume the culprit is that the new_options argument defaults to nil instead of {}: https://github.com/makandra/active_type/blob/v2.3.0/lib/active_type/change_association.rb#L9-L18
new_options
nil
{}
The issue is only revealed when passing a scope proc due to https://github.com/makandra/active_type/blob/v2.3.0/lib/active_type/change_association.rb#L11-L14
Hello foobear,
your assumption seems right. I made a fix that will be released soon as version 2.3.1.
Consider the following model.
Now consider a form model which resolves a post's
user
only to visible users.The above will not work, and instead result in an error:
Instead, passing an (empty) options hash is required to make it work:
I assume the culprit is that the
new_options
argument defaults tonil
instead of{}
: https://github.com/makandra/active_type/blob/v2.3.0/lib/active_type/change_association.rb#L9-L18The issue is only revealed when passing a scope proc due to https://github.com/makandra/active_type/blob/v2.3.0/lib/active_type/change_association.rb#L11-L14