Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Wiki
  • Auxiliary Statements

Auxiliary Statements · Changes

Page history
Updated Auxiliary Statements (markdown) authored Apr 12, 2017 by Lucas Serrano's avatar Lucas Serrano
Hide whitespace changes
Inline Side-by-side
Auxiliary-Statements.md
View page @ f41e8a19
......@@ -4,7 +4,7 @@ Provides a way to write auxiliary statements for use in a larger query. It's rec
### Model
First you need to configure the statements that you want to use. These statements are very similar to scopes, but with a little more options:
First you need to configure the statements you want to use. These statements are very similar to scopes, but with a little more options:
```ruby
# models/user.rb
class User < ActiveRecord::Base
......@@ -17,15 +17,15 @@ class User < ActiveRecord::Base
end
```
The statement is lazy load, so the block is called only when a query requires its usage. To configure your statement, those are the options available:
The statement is lazy load, so the block is called only when a query requires its usage. To configure your statement, these are the options available:
`cte.query` The query that will be performed inside the auxiliary statement (WITH). It most likely to be queries that brings extra information related to the main class, in this case the `User` class.
`cte.query` The query that will be performed inside the auxiliary statement (WITH). It most likely will be one that brings extra information related to the main class, in this case the `User` class.
`cte.attributes` The list of attributes that will be exposed to the main query and after be able to access through the entries fetch. It's read as `The column form the query => The alias exposed`. It accepts join columns in the left side as `'table.column' => 'alias'`.
`cte.attributes` The list of attributes that will be exposed to the main query and after it is able to access through the entries fetch. It's read as `The column form the query => The alias exposed`. It accepts join columns in the left side as `'table.column' => 'alias'`.
`cte.join_type` The type of join between the main query and statement query. By default it's set to `:inner`, that will perform an `INNER JOIN`. The options are `:inner, :left, :right, :full`.
`cte.join` The columns to be used on the join in the main query. It has similar behavior as the attributes, and it's read as `The column from the main query == The column from the statement query`. It accepts join columns in both sides as `'table.column' => 'table.column'`.
`cte.join` The columns used on the join in the main query. It has similar behavior as the attributes, and it's read as `The column from the main query == The column from the statement query`. It accepts join columns in both sides as `'table.column' => 'table.column'`.
### Querying
```ruby
......
Clone repository
  • Wiki
  • Configuring

Data types

  • Enum
  • Interval

Querying

  • Distinct On
  • Auxiliary Statements