Module: Rql::Scope::ParamMethods

Included in:
ParamMethodGroup, RqlScope
Defined in:
lib/rql/scope/param_methods.rb

Instance Method Summary collapse

Instance Method Details

#includes(*attributes) ⇒ Rql::Scope::RqlScope

Includes the specified associated models

Parameters:

  • attributes (Array)

    the associations to include. Use nested hashes to include associations of associations.

Returns:



40
41
42
# File 'lib/rql/scope/param_methods.rb', line 40

def includes(*attributes)
  scope.includes(*attributes)
end

#joins(*attributes) ⇒ Rql::Scope::RqlScope

Joins to the specified associated models

Parameters:

  • attributes (Array)

    the associations to join to. Use nested hashes to chain joins through associations.

Returns:



32
33
34
# File 'lib/rql/scope/param_methods.rb', line 32

def joins(*attributes)
  scope.joins(*attributes)
end

#order(*attributes) ⇒ Rql::Scope::RqlScope

Orders by specified attributes

Parameters:

  • attributes (Array)

    the attributes to order by. Attributes may be a symbol, sql string or a hash specifying attribute and order.

Returns:



24
25
26
# File 'lib/rql/scope/param_methods.rb', line 24

def order(*attributes)
  scope.order(*build_order(attributes))
end

#select(*attributes) ⇒ Rql::Scope::RqlScope

Specifies attributes to be selected from the database

Parameters:

  • attributes (Array)

    the attributes to select

Returns:



16
17
18
# File 'lib/rql/scope/param_methods.rb', line 16

def select(*attributes)
  scope.select(*attributes.map{|attr| scope.derived_attributes[attr] ? scope.eval_rql(&scope.derived_attributes[attr]).as(attr).arel : attr})
end

#where(**conditions) ⇒ Rql::Scope::RqlScope

Filters scope based on specified conditions

Parameters:

  • conditions (Hash)

    A hash of attribute => value conditions to filter on. Use nested hashes to filter on associations. Supports ranges and arrays as values.

Returns:



8
9
10
# File 'lib/rql/scope/param_methods.rb', line 8

def where(**conditions)
  scope.where(build_conditions(conditions))
end