symfony doctrine getArrayResult error 500

TheTom

I'm trying to grab some data from an table which works fine as long as I don't use

->andwhere('s.client_id = :clientid')
->setParameter('clientid', $this->clientId)

I f use the two line above to locate only neccessary data, I end up in a error 500 :(:(

The entity looks like:

class SanitationType
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;


/**
 * @ORM\ManyToOne(targetEntity="Pr\UserBundle\Entity\Client")
 * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
 */
private $client;

/**
 * @ORM\Column(type="string", length=20)
 * @Gedmo\Translatable
 */
private $name;

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 * @Gedmo\Translatable
 */
private $description;

/**
 * @ORM\Column(name="`enabled`", type="boolean")
 */
private $enabled;
    /**
 * @ORM\Column(type="string", length=255, nullable=true)
 */
private $created_by;
    /**
 * @ORM\Column(type="datetime", nullable=true)
 */
private $created;

..............

and my script to grab the data inside the controller looks like this:

$query = $em->createQueryBuilder()
    ->select('s')
    ->from('PrSensorBundle:SanitationType', 's')
    ->where('s.enabled = 1')
    ->andwhere('s.client_id = :client_id')
    ->setParameter('client_id', $this->clientId)
    ->orderBy('s.name', 'ASC')
    ->getQuery();
$results=$query->getArrayResult();

I don't see any error but it is not working at all :(:(

Do I forgot something?

Leo Bedrosian

Couple of things. First, it's not clear what $this->clientId refers to, but if you're trying to reference the id of the client object associated with a SanitationType object, then you'd need to have a public getClient() method on the SanitationType class and a getId() method on the Client class. So obtaining the client id from a SanitationType object $sanitationType then becomes:

$sanitationType->getClient()->getId()

Second, there is no client_id property in the SanitationType class. Doctrine sees the properties of a class as you've defined them. So in this case, to look up a SanitationType object(s) in the database by the id of a Client association(s), you would need to perform an inner join. Your query builder would look like this:

$query = $em->createQueryBuilder()
    ->select('s')
    ->from('PrSensorBundle:SanitationType', 's')
    ->innerJoin('s.client', 'sc')
    ->where('s.enabled = 1')
    ->andwhere('sc.id = :client_id')
    ->setParameter('client_id', $this->clientId)
    ->orderBy('s.name', 'ASC')
    ->getQuery();
$results=$query->getArrayResult();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

->getArrayResult(); alters the value in Symfony?

From Dev

->getArrayResult(); alters the value in Symfony?

From Dev

Doctrine2 Paginator, getArrayResult

From Dev

Symfony - doctrine PreUpdateEventArgs error

From Dev

Symfony production environment throws 500 error: Doctrine\ORM\ORMException 'Unknown Entity namespace alias 'DSBlogBundle'

From Dev

Symfony production environment throws 500 error: Doctrine\ORM\ORMException 'Unknown Entity namespace alias 'DSBlogBundle'

From Dev

Module 500 error in Symfony

From Dev

Doctrine Same query, getResult vs getArrayResult returning different results

From Dev

Call to a member function has() on null 500 with Symfony and Doctrine

From Dev

Symfony 2 Doctrine MS SQL Error

From Dev

Symfony error while doctrine:database:create

From Dev

symfony2 & doctrine orderBy/DQL error

From Dev

symfony doctrine validate entity relations error

From Dev

Memcached Session Symfony 3.0 return error 500

From Dev

Symfony + Doctrine - Define an error message when integrity constraint error

From Dev

Symfony 3.0 Apache Http Error 404 And Http Error 500 response

From Dev

Symfony2 Doctrine: syntax error, unexpected 'function', expecting 'identifier'

From Dev

symfony2 doctrine2 batch processing error with entity

From Dev

Error when use custom DQL function with Doctrine and Symfony2

From Dev

Doctrine error when deploying symfony2 app on pagoda box

From Dev

Symfony2 - Doctrine query for finding posts by slug has an error

From Dev

Query with Criteria Exception error in doctrine2,Symfony2

From Dev

symfony2 doctrine2 batch processing error with entity

From Dev

Symfony2 - Doctrine query for finding posts by slug has an error

From Dev

No identifier specified error Symfony2 Doctrine ORM mapping

From Dev

Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

From Dev

Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

From Dev

i got this error 500 | Internal Server Error | Doctrine_Connection_Mysql_Exception

From Dev

Symfony: Property does not exist - 500 Internal Server Error - ReflectionException

Related Related

  1. 1

    ->getArrayResult(); alters the value in Symfony?

  2. 2

    ->getArrayResult(); alters the value in Symfony?

  3. 3

    Doctrine2 Paginator, getArrayResult

  4. 4

    Symfony - doctrine PreUpdateEventArgs error

  5. 5

    Symfony production environment throws 500 error: Doctrine\ORM\ORMException 'Unknown Entity namespace alias 'DSBlogBundle'

  6. 6

    Symfony production environment throws 500 error: Doctrine\ORM\ORMException 'Unknown Entity namespace alias 'DSBlogBundle'

  7. 7

    Module 500 error in Symfony

  8. 8

    Doctrine Same query, getResult vs getArrayResult returning different results

  9. 9

    Call to a member function has() on null 500 with Symfony and Doctrine

  10. 10

    Symfony 2 Doctrine MS SQL Error

  11. 11

    Symfony error while doctrine:database:create

  12. 12

    symfony2 & doctrine orderBy/DQL error

  13. 13

    symfony doctrine validate entity relations error

  14. 14

    Memcached Session Symfony 3.0 return error 500

  15. 15

    Symfony + Doctrine - Define an error message when integrity constraint error

  16. 16

    Symfony 3.0 Apache Http Error 404 And Http Error 500 response

  17. 17

    Symfony2 Doctrine: syntax error, unexpected 'function', expecting 'identifier'

  18. 18

    symfony2 doctrine2 batch processing error with entity

  19. 19

    Error when use custom DQL function with Doctrine and Symfony2

  20. 20

    Doctrine error when deploying symfony2 app on pagoda box

  21. 21

    Symfony2 - Doctrine query for finding posts by slug has an error

  22. 22

    Query with Criteria Exception error in doctrine2,Symfony2

  23. 23

    symfony2 doctrine2 batch processing error with entity

  24. 24

    Symfony2 - Doctrine query for finding posts by slug has an error

  25. 25

    No identifier specified error Symfony2 Doctrine ORM mapping

  26. 26

    Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

  27. 27

    Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

  28. 28

    i got this error 500 | Internal Server Error | Doctrine_Connection_Mysql_Exception

  29. 29

    Symfony: Property does not exist - 500 Internal Server Error - ReflectionException

HotTag

Archive