Embed a Collection of Forms Error: Could not determine access type for property

后端 未结 8 1305
悲哀的现实
悲哀的现实 2021-02-18 22:34

I am trying to embed collection of Tag forms to Service form, according to this tutorial. Tag and Service entities have many-

8条回答
  •  滥情空心
    2021-02-18 23:10

    Based on Symfony 3.3.10

    I actually faced this problem many and many times, finally once i discovered where this problem was coming from, depending on the name you give to your entity property it can happen that the adder and the remover for your collection property aren't exactly what you are expecting.

    Example: Your entity properity name is "foo" and you would expect the adder to be called "addFoo" and remover "removeFoo", but then all of a sudden the "Could not determine access type for property" appear.

    So you start going into fear searching for w/e problems in your code, instead you just have to look this file inside Symfony core files:

    vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php

    Inside this file there's a method called findAdderAndRemover. Go there with your debugger and you will eventually find out that symfony searches for weird name for your adder/remover, they may actually end with "um" or "on" or "us" depending on the language (human language) you used to name them. Since i'm Italian this happen quite often.

    Watch out for that, since the fix may be as simple as changing the name used for your add/remove method inside your entity to make them match with what Symfony core is looking for.

    This happens to me when i use bin/console doctrine:generate:entities to create the methods automatically for me

提交回复
热议问题