0

i can't to do true query from 2 tables.

   /**
 * Order
 *
 * @ORM\Table(name="order_work")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\OrderWorkRepository")
 */
class OrderWork
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Client", cascade={"persist"})
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
     */
    private $client;

    /**
     * @var string
     *
     * @ORM\Column(name="orderNumber", type="string", length=255)
     */
    private $orderNumber;

and client entity have id, name, surname parameters:

I want to do search by orders column, and by client parameters how i can which query?)

only for orders work this:

$queryBuilder = $this->createQueryBuilder('c')
        ->orWhere('c.orderNumber LIKE :term')
        ->orWhere('c.device LIKE :term')
        ->setParameter('term', '%'.$term.'%');
1
  • I've already spent a few minutes going over your question and it's not very clear. Can you please edit your question and add more details on what is needed? See how to ask a question for more details. I'm giving you -1 until you update. Also in your createQueryBuilder you specify an alias of 'c' - why. Does that represent OrderWork? But for OrderWork you don't have a column of device! So what do you really want to query? Commented Oct 12, 2016 at 18:13

1 Answer 1

1

You have to make a query with a join, which is possible with the querybuilder but i like to use DQL.

public function findOrdersOnClientName($searchTerm)
{
     return $this->getEntityManager()->createQuery(
        'SELECT o, c FROM AppBundle:OrderWork o
        JOIN o.client c
        WHERE c.name LIKE :term'
    )->setParameter('term, '%'. $searchTerm . '%')->getResult();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.