Created
March 8, 2016 17:57
-
-
Save douglaslise/8e8b77133503fdc68ec7 to your computer and use it in GitHub Desktop.
SQL usando Arel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def composicao | |
comp = ProdutoCompos.arel_table | |
prod = Produto.arel_table | |
sql = comp. | |
join(prod).on(comp[:w_id_produto].eq(prod[:w_id])). | |
where(prod[:mob_dt_alteracao].gteq(@vendedor.last_sync). | |
or(comp[:mob_dt_alteracao].gteq(@vendedor.last_sync))). | |
take(params[:limit]). | |
skip(params[:offset]). | |
order(comp[:id_prodcompos]). | |
project(comp[:w_id_produto], comp[:w_id_subproduto], comp[:quantidade], comp[:id_prodcompos].as('w_id'), comp[:sequencia]) | |
render json: ProdutoCompos.find_by_sql(sql).as_json(only: %w(w_id_produto w_id_subproduto quantidade w_id sequencia)) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment