In my custom collection $career_collection->setOrder('career_id','ASC'); not working.

My function is below

public function getAllCareers(){

    $Careers = $this->_careersFactory->create();
    $career_collection = $Careers->getCollection();

    echo $career_collection->getSelect(); exit;
    return $career_collection;

getSelect return the query like below

SELECT `main_table`.* FROM `e25_careers` AS `main_table` WHERE (`active` = '1').

What is the wrong i am doing here


This is correct method


If it is not showing in query. just simply add load();


Then it will show complete query.


You can try below way:

$career_collection->getSelect()->order('career_id ASC');
  • yes this is working to get the query.But how can i return the collection with this order by query.if i add lik ethis $career_collection->Order('career_id ASC'); its not working – Mujahidh May 10 '18 at 5:07

I was facing some syntax error, so resolved by just putting single quotes `


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.