fix issue locomotivecms/wagon#275: with_scope doesn't work with belong_to relationship field type
did
committed Nov 27, 2015
commit d0998731562a42527ec0b0649a1341592dc4942e
Showing 2
changed files with
14 additions
and 1 deletions
locomotive/steam/repositories/content_entry_repository.rb b/lib/locomotive/steam/repositories/content_entry_repository.rb
+5
-1
| @@ | @@ -230,7 +230,11 @@ module Locomotive |
| end | |
| def value_to_id(value) | |
| - | value.respond_to?(:_id) ? value._id : value |
| + | if value.respond_to?(:each) # array |
| + | values_to_ids(value) |
| + | else |
| + | value.respond_to?(:_id) ? value._id : value |
| + | end |
| end | |
| def values_to_ids(value) | |
spec/unit/repositories/content_entry_repository_spec.rb
+9
-0
| @@ | @@ -371,6 +371,15 @@ describe Locomotive::Steam::ContentEntryRepository do |
| end | |
| + | context 'the target value is an arry of content entry' do |
| + | |
| + | let(:value) { [instance_double('TargetContentEntry', _id: 1), instance_double('TargetContentEntry', _id: 2)] } |
| + | let(:conditions) { { 'person.in' => value } } |
| + | |
| + | it { is_expected.to eq([{ _visible: true, content_type_id: 1, 'person_id.in' => [1, 2] }, nil]) } |
| + | |
| + | end |
| + | |
| end | |
| context 'many_to_many fields' do | |