Milos Cuculovic
Milos Cuculovic

Reputation: 20223

Symfony2: Expected argument of type "object", "integer" given

I am trying to create a form with in a drop down list. The data are get from the entity. The problem is that I am getting a Expected argument of type "object", "integer" given exception.

Here is how I am trying to populate the dropdownlist in the form:

public function buildForm(FormBuilder $builder, array $options)
{
   $builder->add('country', 'entity', array(
        'class' => 'SciForumVersion2Bundle:Country',
        'property' => 'country',
    ));
}

In my Entity country, I have

/**
 * @ORM\Column(type="text")
 */
protected $country;

The object I am editing in the form is the user object:

$enquiry = $this->get('security.context')->getToken()->getUser();

In the user entity, I have

/**
 * @ORM\Column(type="integer")
 */
protected $country;

I don't know why I am getting this error.

Upvotes: 1

Views: 1964

Answers (1)

Julien
Julien

Reputation: 9432

There seem to be a problem in your model design, the user's "Country" property should be a Many-To-One association, not an integer (this is why the form builder complains) :

/**
 * @ORM\ManyToOne(targetEntity="Country")
 * @ORM\JoinColumn(name="country_id", referencedColumnName="id")
 **/
private $country;

The "property" option is only used to display the entity choice to the user, Symfony2 uses the first parameter of the "add" method to decide which field of the object to edit.

Upvotes: 2

Related Questions