Fix weak entities case (id is not meaningful attribute) with include.
This commit is contained in:
parent
2eaaa71bd8
commit
e3c45d9b1b
@ -134,7 +134,7 @@ module FastJsonapi
|
|||||||
included_records.concat(serializer_records) unless serializer_records.empty?
|
included_records.concat(serializer_records) unless serializer_records.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
code = "#{record_type}_#{inc_obj.id}"
|
code = "#{record_type}_#{serializer.id_from_record(inc_obj)}"
|
||||||
next if known_included_objects.key?(code)
|
next if known_included_objects.key?(code)
|
||||||
|
|
||||||
known_included_objects[code] = inc_obj
|
known_included_objects[code] = inc_obj
|
||||||
|
@ -158,6 +158,32 @@ describe FastJsonapi::ObjectSerializer do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'id attribute is the same for actors and not a primary key' do
|
||||||
|
before do
|
||||||
|
ActorSerializer.set_id :email
|
||||||
|
movie.actor_ids = [0, 0, 0]
|
||||||
|
class << movie
|
||||||
|
def actors
|
||||||
|
super.each_with_index { |actor, i| actor.email = "actor#{i}@email.com" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
after { ActorSerializer.set_id nil }
|
||||||
|
|
||||||
|
let(:options) { { include: ['actors'] } }
|
||||||
|
subject { MovieSerializer.new(movie, options).serializable_hash }
|
||||||
|
|
||||||
|
it 'returns all actors in includes' do
|
||||||
|
|
||||||
|
expect(
|
||||||
|
subject[:included].select { |i| i[:type] == :actor }.map { |i| i[:id] }
|
||||||
|
).to eq(
|
||||||
|
movie.actors.map(&:email)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'nested includes' do
|
context 'nested includes' do
|
||||||
it 'has_many to belongs_to: returns correct nested includes when serializable_hash is called' do
|
it 'has_many to belongs_to: returns correct nested includes when serializable_hash is called' do
|
||||||
# 3 actors, 3 agencies
|
# 3 actors, 3 agencies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user