Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:15:38+00:00 2026-06-13T19:15:38+00:00

I have two entities: Image and Tags , with a many-to-many relationship. Image has

  • 0

I have two entities: Image and Tags, with a many-to-many relationship.

Image has some fields: code, description, author and tags which implements the many-to-many relationship.

Tag has just two fields: name and images.

I’m building a very general search form, with just an input field where you can write any text and then it will be returned any Image that has that text in its code, description or author fields, or in any of its tags name field.

For the non-relation fields it’s easy. I have in my controller (query is just de GET parameter used for the search):

$em = $this->getDoctrine()->getManager();

$qb = $em->getRepository('MyBundle:Image')->createQueryBuilder('i');

$qb
->where(
      $qb->expr()->like('i.code', $qb->expr()->literal('%'.$request->get('query').'%'))
      )
->orWhere(
      $qb->expr()->like('i.description', $qb->expr()->literal('%'.$request->get('query').'%'))
      )
->orWhere(
      $qb->expr()->like('i.author', $qb->expr()->literal('%'.$request->get('query').'%'))
      );

Now, I don’t know how to proceed for the each name field of the tags.

I had tried to use a virtual field in the Image entity that returned all the tags as a string, but I can’t use it later in the query builder.

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:15:40+00:00Added an answer on June 13, 2026 at 7:15 pm
    SELECT i FROM YourBundle:Image i
    LEFT JOIN i.tags t
    WHERE i.code LIKE :q OR i.desc LIKE :q OR i.author LIKE :q OR t.name LIKE :q
    

    This should work.

    With qb:

    $qb->leftJoin('i.tags', 't')
       ->where($qb->expr()->like('t.name', $qb->expr()->literal('%' . $query . '%')));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities: Patient and Job. Patient has a to-many relationship to Job
I have two entities in coredata: Voice described like: NSString *code NSString *description and
I have two entities, Entity1 and Entity2, on a one to many relationship. On
i have two entities named Parent and Child , linked in a one-to-many relationship.
I have two entities that have a many-to-many relationship; they are mapped with annotations
I have two entities that usually have one-to-many relationship, but in rare cases should
I have two entities, Job and Language , in a many-to-one relationship. The mapping
I have two entities named Category and Article which have a many to many
I have two entities, Note and Tag, that have a many-to-many relationship. I want
I have two entities: Group and ContactInfo. These are connected with a many-to-many relationship

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.