dont create a object for a has one relationship unnecessarily just to fetch id
This commit is contained in:
parent
a018f1d32f
commit
cd1bc0968e
@ -185,12 +185,8 @@ module FastJsonapi
|
||||
return object.id
|
||||
end
|
||||
|
||||
if relationship[:relationship_type] == :has_one
|
||||
record.public_send(relationship[:object_method_name]).try(:id)
|
||||
else
|
||||
record.public_send(relationship[:id_method_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -30,6 +30,10 @@ describe FastJsonapi::ObjectSerializer do
|
||||
p.user_id = id
|
||||
p
|
||||
end
|
||||
|
||||
def photo_id
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
class UserSerializer
|
||||
@ -77,6 +81,10 @@ describe FastJsonapi::ObjectSerializer do
|
||||
a.employee_id = id
|
||||
a
|
||||
end
|
||||
|
||||
def account_id
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
class EmployeeSerializer < UserSerializer
|
||||
|
@ -31,6 +31,10 @@ RSpec.shared_context 'movie class' do
|
||||
mt
|
||||
end
|
||||
|
||||
def advertising_campaign_id
|
||||
1
|
||||
end
|
||||
|
||||
def advertising_campaign
|
||||
ac = AdvertisingCampaign.new
|
||||
ac.id = 1
|
||||
@ -284,7 +288,7 @@ RSpec.shared_context 'movie class' do
|
||||
:owner_id,
|
||||
:owner,
|
||||
:movie_type_id,
|
||||
:advertising_campaign
|
||||
:advertising_campaign_id
|
||||
)
|
||||
|
||||
ActorStruct = Struct.new(:id, :name, :email, :agency_id, :award_ids)
|
||||
|
Loading…
x
Reference in New Issue
Block a user