I used to get my data using this command so the first array is for find variable and the second array is for the order.
So I need to order with specific column:name of test(that is an object that has many columns: id/name ) But I dont know how !! when I enter _test.name I get unrecognized field
->findBy(
array('_id' => $id),
array('_test' =>'ASC')
);
class model1
{
private $_idModel1;
/**
*
* @ORM\ManyToOne()
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id1",
* referencedColumnName="id2")
* })
*/
private $_test;
}
My Answer:
To order by a specific column in Doctrine, you can use the `orderBy` method instead of passing the order in the second array of the `findBy` method. Here's how you can order by the `name` column of the `Test` entity in your example:
php
$repository = $entityManager->getRepository('YourBundle:Model1');
$query = $repository->createQueryBuilder('m')
->where('m.id = :id')
->setParameter('id', $id)
->orderBy('m.test', 'ASC')
->getQuery();
$results = $query->getResult();
In this example, `YourBundle` should be replaced with the actual bundle name where your entities are located, and `Model1` should be replaced with the actual entity name. The `orderBy` method is used to specify the column you want to order by ('m.test' in this case) and the order direction ('ASC' for ascending order).
Make sure to adjust the entity and column names according to your actual entity structure.
Rate this post
3 of 5 based on 1441 votesComments