bettyblocks/betty_resource

View on GitHub
lib/betty_resource/model/property/types/has_and_belongs_to_many.rb

Summary

Maintainability
A
40 mins
Test Coverage
module BettyResource
  class Model
    class Property
      module Types
        module HasAndBelongsToMany
          include Association

          def collection?
            true
          end

          def typecast(record, value)
            filter = {
              'operator' => 'and',
              'conditions' => [
                'path' => [inverse_property.id, model.property(:id).id],
                'predicate' => 'eq',
                'criteria' => record.id
              ]
            }

            target_model.all :filters => [filter]
          end

        end
      end
    end
  end
end