How to retrieve existing object from Database in Nelmio/Alice

441 views Asked by At

I'm trying to retrieve an entity that is already in my test database with a fixed id.

I am defining it like this:

AppBundle\Entity\Template:
  template:
    name: I am a new template
    owner: 1

And I have the setOwner typehinted per the docs.

/**
 * @param User $user
 * @return $this
 */
public function setOwner(User $user)
{
    $this->user = $user;
    return $this;
}

But no dice. I get error Warning: Invalid argument supplied for foreach() in ...

Docs say to do this:

There is one limitation, you can only refer to objects that are defined above in the file. If you want to use an existing object that is already present in your database you can also provide the id of the object. For this to work however the setter method for that property must have a type hint.

Nelmio\Entity\Group: group1: owner: 1 # this will try to fetch the User (as typehinted in Group::setOwner) with id 1

Is there a different typehint format I need or something?

0

There are 0 answers