orm icon indicating copy to clipboard operation
orm copied to clipboard

Cannot load related entities through many to many relations via LEFT_JOIN

Open mrakolice opened this issue 5 years ago • 2 comments

$select->load('many_to_many.has_many') failed with Undefined node 'has_many' exception.

$select->load('[email protected]_many') failed with Undefined relation 'pivotTestModel'.'has_many' exception.

This problem in AbstractLoader#251 in $node->getNode($relation) function.

In debug $node has this structure:

image

Here my models

/**
 * @Entity
 */
class ManyToManyTestModel extends BaseTestModel
{
    public function __construct(array $data = [])
    {
        $this->many_to_many_inverse = new PivotedCollection();
        $this->has_many = new ArrayCollection();
        parent::__construct($data);
    }

    /**
     * @ManyToMany(though=PivotTestModel::class, target=HasManyTestModel::class)
     */
    public $many_to_many_inverse;

    /** @HasMany(target=RelatedModel::class, nullable=true) */
    public $has_many;
}

/**
 * @Entity
 */
class HasManyTestModel extends BaseTestModel
{
    public function __construct(array $data = [])
    {
        $this->many_to_many = new PivotedCollection();

        parent::__construct($data);
    }

    /**
     * @ManyToMany(target=ManyToManyTestModel::class, though=PivotTestModel::class)
     */
    public $many_to_many;

    public $has_many_inverse;
}

/**
 * @Entity
 */
class PivotTestModel
{
    /**  @Column(type="primary") */
    public $id;
}

/**
 * @Entity
 */
class RelatedModel extends BaseTestModel
{
}

mrakolice avatar Feb 12 '20 02:02 mrakolice

----Update----

This behaviour exists when using LEFT_JOIN load method instead of POSTLOAD.

mrakolice avatar Feb 12 '20 06:02 mrakolice

Can you provide isolated example or test case? I'm not sure what Base model is and what are you querying from database.

wolfy-j avatar Feb 12 '20 07:02 wolfy-j