Why does Symfony look for "addWooklyExercise()" instead of "addWeeklyExercise()"

46 Views Asked by At

I changed, by client requirement, an entity textfield (weekly_exercise) to a 1:n relation. Everything works normally so far, but when trying to save the form Symfony looks out for a "changed" method name.

That's the error message I get

Neither the property "weekly_exercise" nor one of the methods "addWooklyExercise()"/"removeWooklyExercise()", "setWeeklyExercise()", "weeklyExercise()", "__set()" or "__call()" exist and have public access in class "XXX\CourseBundle\Entity\Course".

Of course "addWooklyExercise()"/"removeWooklyExercise()" don't exist. I could put them in and proxy to the real methods, but that would only be an ugly hack.

I've been looking through all my files and couldn't find a anything that could be responsible for this issue.

I'm on Symfony 2.5.7 as my client doesn't allow me to update!!

Files involved in the issue https://gist.github.com/mhauptma73

EDIT:

For some reason the method

public function addWooklyExercise(\BDA\CourseBundle\Entity\CourseWeeklyExercise $weeklyExercise)
{

    $this->__initializer__ && $this->__initializer__->__invoke($this, 'addWooklyExercise', array($weeklyExercise));

    return parent::addWooklyExercise($weeklyExercise);
}

is being added in the cache proxy. But there is also the correctly spelled method, before the misspelled one.

2

There are 2 best solutions below

2
habibun On BEST ANSWER

Follow the naming convention like when you add the property for oneToMany then it's plural and for add or remove method change it to singular.

protected $tags;

public function addTag(Tag $tag)
{
    //...
}

public function removeTag(Tag $tag)
{
    // ...
}

See more details read this doc: http://symfony.com/doc/2.7/form/form_collections.html#form-collections-new-prototype

7
dbrumann On

That looks like you have a typo somewhere, probably your Entity, your Form-Type or when outputting a form in a template. Try doing a search over the whole src/ directory for wookly and you will probably find it.