Method: Spider::Model::Query#with_polymorph

Defined in:
lib/spiderfw/model/query.rb

#with_polymorph(type, request = nil) ⇒ self

Requests a polymorph. This means that the mapper will try to differentiate the result into the subclasses given here.

Parameters:

  • Class<BaseModel] (Class<BaseModel] type The polymorph class to look for)

    type The polymorph class to look for

  • request (Request) (defaults to: nil)

    Additional elements of the subclass to request

Returns:

  • (self)


143
144
145
146
147
148
149
150
151
152
# File 'lib/spiderfw/model/query.rb', line 143

def with_polymorph(type, request=nil)
    query = self.class.new(query) unless query.is_a?(self.class)
    @polymorphs << type
    unless request
        request = Request.new
        type.primary_keys.each{ |k| request[k.name] = true }
    end
    @request.with_polymorphs(type, request)
    return self
end