How we can convert direct SQL query to collection ?

SELECT wk_mpauction_winner_data.auction_id, wk_mpauction_winner_data.customer_id, quote_item.created_at AS quote_item_date ,sales_order_item.item_id AS sales_order_item_id , sales_order.state AS order_state
FROM sales_order_item
JOIN sales_order ON sales_order.entity_id= sales_order_item.order_id
JOIN wk_mpauction_winner_data ON wk_mpauction_winner_data.quote_item_id= sales_order_item.quote_item_id
LEFT JOIN quote_item   ON quote_item.item_id= sales_order_item.quote_item_id
LEFT JOIN quote  ON  quote_item.quote_id= quote.entity_id
WHERE quote_item.item_id IS NOT NULL AND quote.customer_id IS NOT NULL
  • Above query is already converted to collection – Rakesh Jesadiya Nov 1 '17 at 13:24
  • @Rakesh no it is just for example ... my question is short and i add above line :) – chiya Nov 1 '17 at 13:27
  • please share your code so user can help for you – Rakesh Jesadiya Nov 1 '17 at 13:28
  • @Rakesh sql =" select * from quote" ... i know for this sql we have collection but if i have custom sql (each sql) how i can do this – chiya Nov 1 '17 at 13:30
  • You need to create model class for module and use your model class as factorymethod to get collection of magento – Rakesh Jesadiya Nov 1 '17 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.