@@ -15,7 +15,7 @@ def new(params = {})
1515 end
1616
1717 def get ( id , scope = scoped )
18- object = scope . where ( primary_key => id ) . first
18+ object = primary_key_scope ( scope , id ) . first
1919 return unless object
2020
2121 object . extend ( ObjectExtension )
@@ -115,10 +115,42 @@ def adapter_supports_joins?
115115 true
116116 end
117117
118+ def format_id ( id )
119+ if primary_key . is_a? Array
120+ RailsAdmin . config . composite_keys_serializer . serialize ( id )
121+ else
122+ id
123+ end
124+ end
125+
126+ def parse_id ( id )
127+ if primary_key . is_a? ( Array )
128+ ids = RailsAdmin . config . composite_keys_serializer . deserialize ( id )
129+ primary_key . each_with_index do |key , i |
130+ ids [ i ] = model . type_for_attribute ( key ) . cast ( ids [ i ] )
131+ end
132+ ids
133+ else
134+ id
135+ end
136+ end
137+
118138 private
119139
140+ def primary_key_scope ( scope , id )
141+ if primary_key . is_a? Array
142+ scope . where ( primary_key . zip ( parse_id ( id ) ) . to_h )
143+ else
144+ scope . where ( primary_key => id )
145+ end
146+ end
147+
120148 def bulk_scope ( scope , options )
121- scope . where ( primary_key => options [ :bulk_ids ] )
149+ if primary_key . is_a? Array
150+ options [ :bulk_ids ] . map { |id | primary_key_scope ( scope , id ) } . reduce ( &:or )
151+ else
152+ scope . where ( primary_key => options [ :bulk_ids ] )
153+ end
122154 end
123155
124156 def sort_scope ( scope , options )
0 commit comments