@@ -14,6 +14,7 @@ class << self
1414 :cachable_relationships_to_serialize ,
1515 :uncachable_relationships_to_serialize ,
1616 :record_type ,
17+ :record_id ,
1718 :cache_length ,
1819 :cached
1920 end
@@ -74,7 +75,8 @@ def relationships_hash(record, relationships = nil)
7475 def record_hash ( record )
7576 if cached
7677 record_hash = Rails . cache . fetch ( record . cache_key , expires_in : cache_length ) do
77- temp_hash = id_hash ( record . id , record_type ) || { id : nil , type : record_type }
78+ id = record_id ? record . send ( record_id ) : record . id
79+ temp_hash = id_hash ( id , record_type ) || { id : nil , type : record_type }
7880 temp_hash [ :attributes ] = attributes_hash ( record ) if attributes_to_serialize . present?
7981 temp_hash [ :relationships ] = { }
8082 temp_hash [ :relationships ] = relationships_hash ( record , cachable_relationships_to_serialize ) if cachable_relationships_to_serialize . present?
@@ -83,7 +85,8 @@ def record_hash(record)
8385 record_hash [ :relationships ] = record_hash [ :relationships ] . merge ( relationships_hash ( record , uncachable_relationships_to_serialize ) ) if uncachable_relationships_to_serialize . present?
8486 record_hash
8587 else
86- record_hash = id_hash ( record . id , record_type ) || { id : nil , type : record_type }
88+ id = record_id ? record . send ( record_id ) : record . id
89+ record_hash = id_hash ( id , record_type ) || { id : nil , type : record_type }
8790 record_hash [ :attributes ] = attributes_hash ( record ) if attributes_to_serialize . present?
8891 record_hash [ :relationships ] = relationships_hash ( record ) if relationships_to_serialize . present?
8992 record_hash
0 commit comments