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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:20:22+00:00 2026-06-17T20:20:22+00:00

Old Query in symfony 1.4 and doctrine 1.2 $user = Doctrine_Query::create() ->from(‘User.u’) ->innerJoin(‘u.State s’)

  • 0

Old Query in symfony 1.4 and doctrine 1.2

$user = Doctrine_Query::create()
                ->from('User.u')
                ->innerJoin('u.State s')
                ->where('u.id = ?', $id)
                ->andWhere('u.state_id = ?', $state_id)
                ->fetchOne();

Now my Query in symfony2:

$repository = $this->getDoctrine()
->getRepository('FrontendAccountBundle:User');

$user = $repository->findBy(array(
    'activationId' => $activation_id), 
    array('state' => 3));

My error is comming up:

Unrecognized field: state

What is the problem?

Edit: reformatted code

Update

User-Entity:

namespace Frontend\AccountBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User implements UserInterface, \Serializable
{

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


    /**
     * @var \State
     *
     * @ORM\ManyToOne(targetEntity="State")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="state_id", referencedColumnName="id")
     * })
     */
    private $state;




    /**
     * Set activationId
     *
     * @param string $activationId
     * @return User
     */
    public function setActivationId($activationId)
    {
        $this->activationId = $activationId;

        return $this;
    }

    /**
     * Get activationId
     *
     * @return string 
     */
    public function getActivationId()
    {
        return $this->activationId;
    }

    /**
     * Set state
     *
     * @param \Frontend\AccountBundle\Entity\State $state
     * @return User
     */
    public function setState(\Frontend\AccountBundle\Entity\State $state = null)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return \Frontend\AccountBundle\Entity\State 
     */
    public function getState()
    {
        return $this->state;
    }

    public function __construct()
    {
        $this->isActive = true;
        $this->salt = md5(uniqid(null, true));
    }

    /**
     * @inheritDoc
     */
    public function getUsername()
    {
        return $this->email;
    }
    /**
     * @see \Serializable::serialize()
     */
    public function serialize()
    {
        return serialize(array(
            $this->id,
        ));
    }

    /**
     * @see \Serializable::unserialize()
     */
    public function unserialize($serialized)
    {
        list (
            $this->id,
        ) = unserialize($serialized);
    }
}

User-Entity:

namespace Frontend\AccountBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * State
 *
 * @ORM\Table(name="state")
 * @ORM\Entity
 */
class State
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

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

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



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set state
     *
     * @param string $state
     * @return State
     */
    public function setState($state)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return string 
     */
    public function getState()
    {
        return $this->state;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return State
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }
}
  • 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-17T20:20:23+00:00Added an answer on June 17, 2026 at 8:20 pm

    The problem is that the variable in the User entity is “state” not “stateId”. You must always use the names from the entity, not the database. The join from User to State also needs to be done since the stateId is in the State entity.

    When joins are needed you are probably better off using queryBuilder or DQL.

    Here’s a post about joins in Doctrine 2 queryBuilder: doctrine 2 query builder and join tables

    Here’s the documentation from the Symfony Book for Doctrine: http://symfony.com/doc/current/book/doctrine.html#entity-relationships-associations

    Here’s an example from my project that is very similar to your problem:

        $uid = 2;
        $rep = $this->getDoctrine()->getRepository('DevondevTrackRTimeBundle:Activity');
        $q = $rep->createQueryBuilder('a')
            ->select ('a.activityId, a.startTime, a.endTime, u.username')
            ->join('a.login','u')
            ->where('u.id = :uid')
            ->setParameter('uid', $uid)
            ->getQuery();
    
        $acts = $q->getResult();
    

    If I didn’t need anything from the user table the query could be written as

        $uid = 2;
        $rep = $this->getDoctrine()->getRepository('DevondevTrackRTimeBundle:Activity');
        $q = $rep->createQueryBuilder('a')
            ->where('a.login = :uid')
            ->setParameter('uid', $uid)
            ->getQuery();
    
        $acts = $q->getResult();
    

    This is your query reworked in the same way:

        $rep = $this->getDoctrine()->getRepository('FrontendAccountBundle:User');
        $q = $rep->createQueryBuilder('u')
            ->join('u.state','s')
            ->where ('u.id = :uid')
            ->andWhere ('s.stateId = :sid')
            ->setParameters(array('uid' => $id, 'sid' => $state_id))             
            ->getQuery(); 
    
        $user = $q->getSingleResult();        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a very old query from SQL to DQL, and part of
In old mysql code, I had a query below which worked perfectly which is
I am busy converting a query using the old style syntax to the new
I'm translating an old database SyBase to MySQL and I have this DDL Query:
I have a piece of old code that used a query using WQL to
Old Title: Prevent dynamically created control from retaining value Old Info: The reason I
i'm trying to get optimize an very old query that i can't wrap my
I've noticed that some sites (including the old http://careers.stackoverflow.com 1.0) have query strings that
It's getting old rewriting report code for Rails applications. Ya have to create the
I am re-writing a query that was generated by Business Objects and uses old-fashioned

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.