-
Notifications
You must be signed in to change notification settings - Fork 36
Should still able to set other reflection successfully #62
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
Conversation
ea41c2c to
c9ad377
Compare
| end | ||
| end | ||
|
|
||
| context "when using other reflection" do |
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.
What is other? Can we be more specific?
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 specify one example underneath in it aka ActiveRecord::Reflection::ThroughReflection
| def set_owner_attributes(record) | ||
| super | ||
| if reflection.foreign_integer_type && reflection.integer_type | ||
| if reflection.try(:foreign_integer_type) && reflection.try(:integer_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.
Hmm. My general feeling is that the use of try is a bit lazy => why not simply have those methods defined but return nil to that we end up with reflections continuing to look similar, versus needing to remember that we need to guard against some differences.
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.
you are more suggesting to something like this?
def foreign_integer_type(reflection)
if reflection.respond_to? (:foreign_integer_type)
reflection.foreign_integer_type
else
nil
end
end
or simple
def foreign_integer_type(reflection)
reflection.try(: foreign_integer_type)
end
which feel like the same though
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.
Also, I do not want to just adding moreattr_accessor to ThroughReflection in here https://github.com/clio/polymorphic_integer_type/blob/master/lib/polymorphic_integer_type/extensions.rb#L5-L8 in case there is more reflection I am not aware of.
MrJakeReid
left a comment
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've read Adam's suggestion and while I wouldn't be opposed to it, I don't inherently see the value in adding a method definition to guard against the edge case that's demonstrated in the specs. I think checking with try is acceptable, and if there are more edge cases then I'd be open to the refactor.
The error caught my attention while implementing another ticket.
Making sure the
PolymorphicForeignAssociationExtensionwill be compatible with any reflection (in this case,ActiveRecord::Reflection::ThroughReflection)Since this is such a minor fix, will not bump the version but re-release after the merge.