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 7958777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:28:23+00:00 2026-06-04T04:28:23+00:00

Would be possible to check if an association exists before issuing a query in

  • 0

Would be possible to check if an association exists before issuing a query in Doctrine2? Example:

/**
 * @ORM\Entity
 */
class Product
{
    /**
     * @ORM\OneToMany(targetEntity="Feature", inversedBy="product")
     */
    public $features;
}

I’d like to check (actually without issuing the query itself) it the association product.features exists.

EDIT: Out of curiosity i’m writing a service (an helper, really) to do some collection filtering based on GET paramters:

public function initialize($entityName, $key)
{
    // Defaults are empty values and empty collection
    $this->values     = array();
    $this->collection = new ArrayCollection();

    // If "$key" GET parameter is null or blank return this instance
    if(is_null($value = $this->request->get($key))
        || strlen(trim($value)) == 0) return $this;

    // Split the parameter value based on separator (typically a comma)
    $re = '/\s*' . $this->separator . '\s*/';

    // Return this instance if no values are found
    if(!($set = preg_split($re, $value, 0, PREG_SPLIT_NO_EMPTY))) return $this;

    // Guess the repository fully qualified name and entity name
    $guesser    = $this->getManagementGuesser();
    $repoName   = $guesser->guessRepositoryName();
    $entityName = $guesser->guessEntityName();

    // Get the repository for the entity and create the builder
    $qb = $this->getRepository($repoName)->createQueryBuilder('e');

    // Check if a relation named $key exists and throw a LogicException
    $exists = $this->getEntitiesUtility()->checkRelation($entityName, $key);
    if(!$exists) throw new \LogicException("Relation named '$key' not found.");

    // Other stuff
}

The relavant part would be:

$this->getEntitiesUtility()->checkRelation($entityName, $relationName);
  • 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-04T04:28:23+00:00Added an answer on June 4, 2026 at 4:28 am
    // $em being your EntityManager..
    
    if ($em->getClassMetadata($className)->getAssociationMapping($fieldName))
    {
       ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would it be possible to add a new operator to the String class that
I would like to know if it's possible to check if URL is indexed
is it possible to check if pdf is password protected using ghostscript? what would
This seems like it would be possible. protected SameObjectTypeAsInputParameterObjectType GetAValue(someObject,TypeOrReturnObjectYouWant){ //check to see if
Is it somehow possible to check if a file exists, without actually downloading it?
I would like to know if it's possible to check the current time of
I would like to know if it would be possible to replicate the effect
I was wondering if it would be possible to do this: $var = '$something
Hey, I'm just wondering if it would be possible to convert videos to mp3
Would it be possible rollback transactions using Transactionlog file for a particular record? I

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.