Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship hasManyToMany eager fail when no elements. #5

Open
Surt opened this issue Jul 1, 2015 · 1 comment
Open

Relationship hasManyToMany eager fail when no elements. #5

Surt opened this issue Jul 1, 2015 · 1 comment

Comments

@Surt
Copy link
Contributor

Surt commented Jul 1, 2015

On a hasManytoMany relationship it fails when one of the parent element does not have relationship:

On a model:

        $this->hasManyToMany(
            "id",
            'App\Tag\Models\ElementTag',
            "element_id", "tag_id",
            'App\Tag\Models\Tag',
            "id", array('alias' => 'tags')
        );

When that parent model does not have TagsElements it does fail to fetch the relationship.

 $parentModelResults = Loader::fromResultset($parentModelResults, [
                'tags' => function (QueryBuilder $builder) {
                    $builder->where('App\Tag\Models\ElementTag.element_type = "parentModelType"');
                },
Phalcon\Mvc\Model\Exception: Unknown model or alias 'App\Tag\Models\ElementTag' (1), when preparing: SELECT [App\Tag\Models\Tag].* FROM [App\Tag\Models\Tag] WHERE ([id] IN (:phi0:, :phi1:)) AND (App\Tag\Models\ElementTag.element_type = "playingfield")
@stibiumz
Copy link
Owner

stibiumz commented Jul 2, 2015

That's because an extra query is needed to fetch the keys needed to relate tables.

I did not think about it because joining tables are mainly used to build a 'key to key relation'
Do you have any suggestion about fixing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants