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

Is it just me or are the examples in the documentation extremely confusing? #25

Closed
flyingL123 opened this issue Mar 18, 2019 · 3 comments

Comments

@flyingL123
Copy link

This looks like an amazing library and exactly what I need. However, I've literally read the examples 50 times trying to figure out how to accomplish what I need, but I just can't understand it. First of all, does this library work for my situation? And if so, what is the proper relationship definition?

I'm have the following relationship:

Product -> belongsTo -> SSIN -> belongsToMany -> stockableItems

I am trying to set up a stockableItems relationship on the Product model.

I can not for the life of me figure out the right way to do this. Can anyone help? Here is something I tried, using the advanced hasManyDeepFromRelations method:

public function stockableItems() {
    return $this->hasManyDeepFromRelations(
        $this->ssin(),
        (new Ssin)->stockableItems()
    );
}

This seemed to work, but then I noticed that when I retrieved $product->stockableItems, the stockableItems were actually being returned with the wrong ID. For some reason they were being assigned an ID equal to the ssin_id from the ssin_stockable_item join table.

I'm not sure if this is a bug or if my setup is wrong. Also, I probably don't even need to use the hasManyDeepFromRelations method, but as stated above, I can't figure out from the documentation how this relationship is supposed to be set up.

@staudenmeir
Copy link
Owner

The package does support this relationship, but only in Laravel 5.8:

public function stockableItems()
{
    return $this->hasManyDeep(
        StockableItem::class, [SSIN::class, 'ssin_stockable_item'], ['id'], ['ssin_id']
    );
}

There's a limitation in the underlying HasManyThrough relationship that causes the issue with incorrects IDs when the first segment is a BelongsTo relationship.

Can you upgrade to Laravel 5.8?

@flyingL123
Copy link
Author

Thanks a lot for the reply. I should be able to upgrade to 5.8 soon. I will report back when I do. I really appreciate the help.

@flyingL123
Copy link
Author

@staudenmeir I upgraded to 5.8, and it now works great. Thank you.

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