title: Symfony3 - "Unrecognized field" exception when I want to pull entries based on the value of a Many-to-One relation property
body: <p><br>
  I want to display records from an entity, but only records that have the loginID value equal to the current user's ID. In the Events entity, loginid is a many-to-one property.<br><br>
  I have the following Events entity:
      
  
  <pre><code>namespace Vendor\MyBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * Events
   *
   * @ORM\Table(name="events")
   * @ORM\Entity
   */
  class Events
  {
      /**
       * @var string
       *
       * @ORM\Column(name="EventName", type="string", length=255, nullable=false)
       */
      private $eventname;
  
      /**
       * @var string
       *
       * @ORM\Column(name="Location", type="string", length=255, nullable=false)
       */
      private $location;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="StartDate", type="datetime", nullable=false)
       */
      private $startdate;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="EndDate", type="datetime", nullable=false)
       */
      private $enddate;
  
      /**
       * @var boolean
       *
       * @ORM\Column(name="Status", type="boolean", nullable=false)
       */
      private $status;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="eventID", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $eventid;
  
  
  
      /**
       * Set eventname
       *
       * @param string $eventname
       *
       * @return Events
       */
      public function setEventname($eventname)
      {
          $this-&gt;eventname = $eventname;
  
          return $this;
      }
  
      /**
       * Get eventname
       *
       * @return string
       */
      public function getEventname()
      {
          return $this-&gt;eventname;
      }
  
      /**
       * Set location
       *
       * @param string $location
       *
       * @return Events
       */
      public function setLocation($location)
      {
          $this-&gt;location = $location;
  
          return $this;
      }
  
      /**
       * Get location
       *
       * @return string
       */
      public function getLocation()
      {
          return $this-&gt;location;
      }
  
      /**
       * Set startdate
       *
       * @param \DateTime $startdate
       *
       * @return Events
       */
      public function setStartdate($startdate)
      {
          $this-&gt;startdate = $startdate;
  
          return $this;
      }
  
      /**
       * Get startdate
       *
       * @return \DateTime
       */
      public function getStartdate()
      {
          return $this-&gt;startdate;
      }
  
      /**
       * Set enddate
       *
       * @param \DateTime $enddate
       *
       * @return Events
       */
      public function setEnddate($enddate)
      {
          $this-&gt;enddate = $enddate;
  
          return $this;
      }
  
      /**
       * Get enddate
       *
       * @return \DateTime
       */
      public function getEnddate()
      {
          return $this-&gt;enddate;
      }
  
      /**
       * Set status
       *
       * @param boolean $status
       *
       * @return Events
       */
      public function setStatus($status)
      {
          $this-&gt;status = $status;
  
          return $this;
      }
  
      /**
       * Get status
       *
       * @return boolean
       */
      public function getStatus()
      {
          return $this-&gt;status=true;
      }
  
      /**
       * Get eventid
       *
       * @return integer
       */
      public function getEventid()
      {
          return $this-&gt;eventid;
      }
  
      /**
       * Get web path to upload directory.
       * 
       * @return string
       * Relative path.
       */
      protected function getUploadPath()
      {
          return 'uploads/eventCovers';
      }
  
      /**
       * Get absolute Path.
       * 
       * @return string
       * Absolute path.
       */
      protected function getUploadAbsolutePath()
      {
          return __DIR__ . '/../../../../web/' . $this-&gt;getUploadPath();
      }
  
      /**
       * Get web path to a cover.
       * 
       * @return null|string
       * Relative path.
       */
      public function getCoverWeb()
      {
          return NULL === $this-&gt;getCover()
                  ? NULL
                  : $this-&gt;getUploadPath() . '/' . $this-&gt;getCover();
      }
  
      /**
       * Get web path on disk to a cover.
       * 
       * @return null|string
       * Absolute path.
       */
      public function getCoverAbsolute()
      {
          return NULL === $this-&gt;getCover()
                  ? NULL
                  : $this-&gt;getUploadAbsolutePathPath() . '/' . $this-&gt;getCover();
      }
  
      /**
       * Set validation for max file size of 2 MB.
       * 
       * @Assert\File(maxSize="2M")
       */
      private $file;
  
      /**
       * Sets file.
       * 
       * @param UploadedFile $file
       */
      public function setFile(UploadedFile $file = NULL) 
      {
          $this-&gt;file =  $file;
      }
  
      /**
       * Get file.
       * 
       * @return UploadedFile
       */
      public function getFile()
      {
          return $this-&gt;file;
      }
  
      /**
       * 
       * Upload a cover file.
       */
      public function upload()
      {
          //file property can be empty
          if (NULL === $this-&gt;getFile()){
              return;
          }
          $filename=$this-&gt;getFile()-&gt;getClientOriginalName();
  
          //move the uploaded file to the target directory using the original name
          $this-&gt;getFile()-&gt;move(
                  $this-&gt;getUploadAbsolutePath(),
                  $filename);
  
          //set the cover
          $this-&gt;setCover($filename);
  
          //cleanup
          $this-&gt;setFile();
      }
  
      /**
       * @var string
       * 
       * @ORM\Column(name="Cover", type="string", length=255, nullable=true)
       */
      private $cover;
  
  
      /**
       * Set cover
       *
       * @param string $cover
       *
       * @return Events
       */
      public function setCover($cover)
      {
          $this-&gt;cover = $cover;
  
          return $this;
      }
  
      /**
       * Get cover
       *
       * @return string
       */
      public function getCover()
      {
          return $this-&gt;cover;
      }
      /**
       * @var \Vendor\MyBundle\Entity\Logins
       */
      private $loginid;
  
      /**
       * @var \Vendor\MyBundle\Entity\WishList
       */
      private $wishlistid;
  
  
      /**
       * Set loginid
       *
       * @param \Vendor\MyBundle\Entity\Logins $loginid
       *
       * @return Events
       */
      public function setLoginid(\Vendor\MyBundle\Entity\Logins $loginid = null)
      {
          $this-&gt;loginid = $loginid;
  
          return $this;
      }
  
      /**
       * Get loginid
       *
       * @return \Vendor\MyBundle\Entity\Logins
       */
      public function getLoginid()
      {
          return $this-&gt;loginid;
      }
  
      /**
       * Set wishlistid
       *
       * @param \Vendor\MyBundle\Entity\WishList $wishlistid
       *
       * @return Events
       */
      public function setWishlistid(\Vendor\MyBundle\Entity\WishList $wishlistid = null)
      {
          $this-&gt;wishlistid = $wishlistid;
  
          return $this;
      }
  
      /**
       * Get wishlistid
       *
       * @return \Vendor\MyBundle\Entity\WishList
       */
      public function getWishlistid()
      {
          return $this-&gt;wishlistid;
      }
  }
  </code></pre>
  
  <p>and the following indexAction in my controller:</p>
  
  <pre><code>namespace Vendor\MyBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Vendor\MyBundle\Entity\Events;
  use Vendor\MyBundle\Form\EventsType;
  
  /**
   * Events controller.
   *
   * @Route("/sec/events")
   */
  class EventsController extends Controller
  {
      /**
       * Lists all Events entities.
       *
       * @Route("/", name="sec_events_index")
       * @Method("GET")
       */
      public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $user = $this-&gt;getUser();
          $events = $em-&gt;getRepository('VendorMyBundle:Events')-&gt;findBy(array('loginid' =&gt; $user-&gt;getLoginid()));
  
          return $this-&gt;render('events/index.html.twig', array(
              'events' =&gt; $events,
          ));
      }
  }
  </code></pre>
  
  <p>However I am thrown the error: <em>Unrecognized field: loginid</em> even though that is the name of the field/property in the Events class. <br>
  I looked <a href="https://stackoverflow.com/questions/4619071/doctrine2-findby-relationship-object-triggers-string-conversion-error">here</a> and I do have the code used as it says in there. <br>
  What am I missing?<br>
  Any help would be greatly appreciated! <br></p>