Skip to content

Instantly share code, notes, and snippets.

@douglaslise
Created March 8, 2016 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglaslise/8e8b77133503fdc68ec7 to your computer and use it in GitHub Desktop.
Save douglaslise/8e8b77133503fdc68ec7 to your computer and use it in GitHub Desktop.
SQL usando Arel
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