Search code examples
mysqlsymfonydoctrineentity

Error: Call to a member function setStats() on a non-object


I am trying to update a single data in my entity class, but the doctrine is always returning this error

Error: Call to a member function setStats() on a non-object**
        $em = $this->getDoctrine()->getManager();

        $result = $em->getRepository('MyBundle:UserStats')->findBy(array('ownerPhone' => 1002));

        if( isset($result) && $result !== false ) {
        echo $result->setConditionState(0); // ConditionState is a boolean condition which i want to set it to false

        }
        $em->flush();

My entity class for conditionState---

/**
     * Set conditionState
     *
     * @param boolean $conditionState
     *
     * @return UserStats
     */
    public function setConditionState($conditionState)
    {
        $this->conditionState = $conditionState;

        return $this;
    }

    /**
     * Get conditionState
     *
     * @return boolean
     */
    public function getConditionState()
    {
        return $this->conditionState;
    }

Do anyone have an idea where I am making the mistake?


Solution

  • findBy method returns an array. Use findOneBy instead.