orm icon indicating copy to clipboard operation
orm copied to clipboard

Two similar entity properties generated in runtime/cache/cycle.php

Open anlamas opened this issue 4 years ago • 1 comments

If u manually specify name of inner key in a relation

/**
* @Cycle\Column(type="bigPrimary")
*/
protected int $id;

/**
* @Cycle\Column(type="bigInteger", nullable=true)
*/
private ?int $parentId;

/**
* @Cycle\Relation\BelongsTo(target="ProductCategory", innerKey="parent_id", nullable=true, fkAction="SET NULL")
*/
private ?ProductCategory $parent;

You get this

'id' => 'id',
'parentId' => 'parent_id',
'parent_id' => 'parent_id',

Expected result

'id' => 'id',
'parentId' => 'parent_id',

anlamas avatar Mar 04 '21 16:03 anlamas

The documentation says:

innerKey -- Inner key in source entity. Defaults to {relationName}_{outerKey}

Therefore, for your case it will be more correct like this:

/**
* @Cycle\Relation\BelongsTo(target="ProductCategory", innerKey="parentId", nullable=true, fkAction="SET NULL")
*/
private ?ProductCategory $parent;

But be careful: in your example, the settings for the $parentId field will be different from those implied for the BelongsTo relation. Among other things, the BelongsTo relaction sets the default value to NULL for the innerKey field.

roxblnfk avatar Mar 18 '21 12:03 roxblnfk