3

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();
    $career_collection->addFieldToFilter('active',1)->setOrder('career_id','ASC');
    //$career_collection->setOrder('career_id','ASC');

    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

3

This is correct method

$career_collection->addFieldToFilter('active',1)->setOrder('career_id','ASC');

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

$career_collection->addFieldToFilter('active',1)->setOrder('career_id','ASC')->load(); 

Then it will show complete query.

1

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
0

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

$collection->setOrder('`career_id`','ASC');

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.