Skip to content

Issue with form helper trying to load schema from non-existing database table #11

@k-risc

Description

@k-risc

When not using dedicated table classes for the different entity types, and setting their "table" to the name of the shared table in the database, I get error messages about database tables not being found.

It seems the property _registryAlias, returned with getSource() is set to the name of the concrete entity class, not the base class.

Any code using that trying to load the corresponding database table, e.g. in the FormHelper/EntityContext, will throw that error, because it tries to load a non-existent database table.

My solution would be to define in the base entity class

    public function __construct(array $properties = [], array $options = [])
    {
        parent::__construct($properties, array_merge($options, [
            'source' => 'Compliancetasks',
        ]));
    }

This then sets the source in all special entity classes extending the base class correctly.

What I am wondering: is this really necessary and just not documented that this has to be done? Or is it not necessary and I am doing something wrong?

The StiBehavior, when building its type map, for each entry derives some $alias from the $entityName in order to check

  • whether the special entity class exists
  • in case a table happens to exist matching the special entity name, and that table is not the base table, and that table has its own entity class, being different from the currently added special entity, it throws an exception
  • but then it also stores that alias in the config and uses it as the registry alias of special entity instances, so each instance has, as its source, something matching its class name, e.g. chefs, instead of the base name, e.g. cooks.

One solution would be to use the tableof the behavior config, which should be the base table, as the source of the special entity instances when creating them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions