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:

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

Returns:

  • a new scope including the specified associations



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:

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

Returns:

  • a new scope joining the specified associations



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:

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

Returns:

  • a new scope ordered by the specified attributes



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:

  • the attributes to select

Returns:

  • a new scope selecting the specified attributes



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:

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

Returns:

  • a new scope filtered by the specified conditions



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

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