nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
310 stars 57 forks source link

Problém s relací #359

Closed krausv closed 4 years ago

krausv commented 4 years ago

Dobrý den,

omlouvám se za triviální dotaz. Bohužel se s tím ale trápím už několik hodin a nevím, jak z toho ven.

Mám tyto dvě entity:

/**
 * @property int $id {primary}
 * @property string $title
 * @property string $description
 * @property Village $village {m:1 Village, oneSided=true}
 * @property DateTimeImmutable $createdAt {default now}
 * @property int $status
 * @property OneHasMany|Table[] $tables {1:m Table::$project}
 */
class Project extends Entity
{
   const STATUS_OPEN = 1;
   const STATUS_ARCHIVED = 2;
}

a

/**
 * @property int $id {primary}
 * @property string $title
 * @property Project $project {m:1 Project::$tables}
 */
class Table extends Entity
{
}

Problém je v tom, že mi to vrací Relationship {1:m} in App\Orm\Project::$tables points to unknown 'App\Orm\Table' entity.

Nevěděl by někdo, proč? V PHPStormu jdou názvy entit "prokliknout". Namespace je také v pořádku.

Za jakoukoliv radu děkuji

mabar commented 4 years ago

Is Table autoloadable? Also, you should have defined a repository for every entity

final class TablesRepository extends Repository
{
    static function getEntityClassNames()
    {
        return [Table::class];
    }
}
mabar commented 4 years ago

@hrach Maybe there would be helpful to add message "Ensure repository for '{$entity}' is defined and is discoverable by orm."

https://github.com/nextras/orm/blob/master/src/Entity/Reflection/MetadataParser.php#L360-L362

krausv commented 4 years ago

Hi, thanks for your reply.

My TablesRepository class looks like

use Nextras\Orm\Repository\Repository;

final class TablesRepository extends Repository
{
    static function getEntityClassNames(): array
    {
        return [Table::class];
    }
}

But Table class is not in DIC. I'll try to figure out why it's missing. Thank you for the advice!

PS: I apologize for being my post in Czech. Two days without sleep are hard :/

hrach commented 4 years ago

This error basically means:

Feel free to comment with more specific description of error and I will try to answer more specifically.