Skip to content

Commit 5e01a93

Browse files
committed
Update comments regarding lazy_association and TODOs
1 parent ff5ab21 commit 5e01a93

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

lib/active_model/serializer/concerns/caching.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def object_cache_keys(collection_serializer, adapter_instance, include_directive
193193
cache_keys << object_cache_key(serializer, adapter_instance)
194194

195195
serializer.associations(include_directive).each do |association|
196+
# TODO(BF): Process relationship without evaluating lazy_association
196197
association_serializer = association.lazy_association.serializer
197198
if association_serializer.respond_to?(:each)
198199
association_serializer.each do |sub_serializer|

lib/active_model/serializer/lazy_association.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ def virtual_value
4040
cached_result[:virtual_value] || reflection_options[:virtual_value]
4141
end
4242

43-
# NOTE(BF): Kurko writes:
44-
# 1. This class is doing a lot more than it should. It has business logic (key/meta/links) and
45-
# it also looks like a factory (serializer/serialize_object/instantiate_serializer/serializer_class).
46-
# It's hard to maintain classes that you can understand what it's really meant to be doing,
47-
# so it ends up having all sorts of methods.
48-
# Perhaps we could replace all these methods with a class called... Serializer.
49-
# See how association is doing the job a serializer again?
50-
# 2. I've seen code like this in many other places.
51-
# Perhaps we should just have it all in one place: Serializer.
52-
# We already have a class called Serializer, I know,
53-
# and that is doing things that are not responsibility of a serializer.
5443
def serializer_class
5544
return @serializer_class if defined?(@serializer_class)
5645
serializer_for_options = { namespace: namespace }
@@ -82,8 +71,6 @@ def serialize_object!(object)
8271
end
8372
end
8473

85-
# NOTE(BF): This serializer throw/catch should only happen when the serializer is a collection
86-
# serializer. This is a good reason for the reflection to have a to_many? type method.
8774
def instantiate_serializer(object)
8875
serializer_options = association_options.fetch(:parent_serializer_options).except(:serializer)
8976
serializer_options[:serializer_context_class] = association_options.fetch(:parent_serializer).class

lib/active_model_serializers/adapter/json_api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def process_resource(serializer, primary, include_slice = {})
257257

258258
def process_relationships(serializer, include_slice)
259259
serializer.associations(include_slice).each do |association|
260+
# TODO(BF): Process relationship without evaluating lazy_association
260261
process_relationship(association.lazy_association.serializer, include_slice[association.key])
261262
end
262263
end

lib/active_model_serializers/adapter/json_api/relationship.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def as_json
3333

3434
private
3535

36+
# TODO(BF): Avoid db hit on belong_to_ releationship by using foreign_key on self
3637
def data_for(association)
3738
if association.collection?
3839
data_for_many(association)
@@ -42,6 +43,7 @@ def data_for(association)
4243
end
4344

4445
def data_for_one(association)
46+
# TODO(BF): Process relationship without evaluating lazy_association
4547
serializer = association.lazy_association.serializer
4648
if (virtual_value = association.virtual_value)
4749
virtual_value
@@ -53,6 +55,7 @@ def data_for_one(association)
5355
end
5456

5557
def data_for_many(association)
58+
# TODO(BF): Process relationship without evaluating lazy_association
5659
collection_serializer = association.lazy_association.serializer
5760
if collection_serializer.respond_to?(:each)
5861
collection_serializer.map do |serializer|

0 commit comments

Comments
 (0)