-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Associations refactoring #985
Associations refactoring #985
Conversation
3c3ade1
to
3806e36
Compare
3806e36
to
7b27cc2
Compare
9b59060
to
0768d04
Compare
assert_equal({}, options) | ||
assert_nil serializer | ||
elsif name == :roles | ||
assert_equal({embed: :ids}, options) | ||
when :roles |
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.
👍
include Configuration | ||
include Associations |
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.
👍
Awesome @bolshakov, keep up the good work. |
7bfd542
to
f88728e
Compare
5c01cea
to
e790e7d
Compare
I have couple of questions: Association definition syntax.It allows to write multiple associations at once: has_many :comments, :posts, serializer: CoolSerializer What does it mean? Can we make backward incompatible change and disallow to specify multiple associations at once. has_many :comments
has_many :posts, serializer: PostSerializer Underscope prefixesI can't realize why they are used in all the code. What reason to write |
@joaomdmoura could you review? |
aeb81b2
to
0bc0247
Compare
@bolshakov, answering your questions:
ex: module ActiveModel
class Serializer
class << self
attr_accessor :_attributes
end
def self.attributes(*attrs)
attrs = attrs.first if attrs.first.class == Array
@_attributes.concat attrs
@_attributes.uniq!
end
def another_method_using_attributes
p @_attributes
end
end
end |
@joaomdmoura thanks for explanation!
For me that behavior looks error prone: has_many :comments, :posts, serializer: CoolSerializer From the other hand if I think it would be convenient to maintain same interface as ActiveRecord. |
LGTM. |
Another options may be |
@joaomdmoura thought? |
Sorry for taking so long @bolshakov, I was on a business trip, but I'm willing to merge it, can you rebase it with master? |
* Move all associations related code from Serializer class to Associations module * Introduce Reflection class hierarchy * Introduce Association class * Rid off Serializer#each_association * Introduce Serializer#associations enumerator
0bc0247
to
2952a33
Compare
Done, Thank you! |
Merged. Thank you! 😄 |
Associations implementation refactoring
Woo hoo! |
This refactoring brakes internal API, so it affect custom adapters
Associations introspection
Before refactoring:
After refactoring:
Reflections introspection
Instead of
Serializer._associations
we introducedSerializer._reflections
, which is an array ofActiveModel::Serializer::Reflection