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

change_assocation with only a scope proc fails with an error #168

Closed
foobear opened this issue Sep 22, 2022 · 1 comment
Closed

change_assocation with only a scope proc fails with an error #168

foobear opened this issue Sep 22, 2022 · 1 comment

Comments

@foobear
Copy link
Member

foobear commented Sep 22, 2022

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.

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

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

@foobear foobear changed the title change_assocation with only a scope proc breaks change_assocation with only a scope proc fails with an error Sep 22, 2022
@FLeinzi
Copy link
Contributor

FLeinzi commented Oct 6, 2022

Hello foobear,

your assumption seems right. I made a fix that will be released soon as version 2.3.1.

@FLeinzi FLeinzi closed this as completed Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants