Skip to content

Deeply nesting relation using via does not work #11898

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Deeply nesting relation using via does not work #11898

wants to merge 3 commits into from

Conversation

cebe
Copy link
Member

@cebe cebe commented Jul 5, 2016

This PR adds a failing test from #7625 by @fernandezekiel and adjusted test data that fails even one of the existing relation tests.

these test failures cover the issue described in #5341

fernandezekiel and others added 2 commits July 4, 2016 15:35
some tests accidentally passed because they matched the primary key
which is named `id` in all tables against similar primary key values.
as soon as primary key values differ among tables, these tests are
failing.

reproduce #5341 on existing tests...
@cebe cebe self-assigned this Jul 5, 2016
@cebe cebe mentioned this pull request Jul 5, 2016
@cebe
Copy link
Member Author

cebe commented Jul 5, 2016

The problem lies in ActiveRelationTrait bucket building among these lines:

if (isset($viaModels, $viaQuery)) {
$buckets = $this->buildBuckets($models, $this->link, $viaModels, $viaQuery->link);
} else {
$buckets = $this->buildBuckets($models, $this->link);
}
$this->indexBy = $indexBy;
if ($this->indexBy !== null && $this->multiple) {
$buckets = $this->indexBuckets($buckets, $this->indexBy);
}
$link = array_values(isset($viaQuery) ? $viaQuery->link : $this->link);

@cebe cebe added this to the 2.0.10 milestone Jul 5, 2016
@cebe cebe modified the milestones: 2.0.11, 2.0.10 Oct 13, 2016
@cebe cebe modified the milestones: 2.0.12, 2.0.11 Dec 3, 2016
@cebe
Copy link
Member Author

cebe commented Apr 4, 2017

It is currently not possible. I am planning to try fixing this for 2.0.13

@cebe cebe modified the milestones: 2.0.13, 2.0.12 Apr 4, 2017
@cebe cebe modified the milestones: 2.0.13, 2.0.14 Oct 13, 2017
@samdark samdark modified the milestones: 2.0.14, 2.0.15 Feb 11, 2018
@ztdan4ik
Copy link

ztdan4ik commented Jun 5, 2018

Hi there!
Thanks for your great work!
Need this fix
Hope soon we will see it :)

@ztdan4ik
Copy link

ztdan4ik commented Jun 5, 2018

@GlyphDataServices
I've problem exactly with via() and joinWith()

My problem is same like in tests 7ec045b#diff-dca0f800c4dd790fb5d5914365547549R1194

See the screenshots

  1. Model relations
  2. ModelSearch
  3. Result

In this case work fine But this way looks not good.

@ztdan4ik
Copy link

ztdan4ik commented Jun 5, 2018

@GlyphDataServices
Thanks for your reply
See please my schema

Dummy param not solving the problem. First it's asking for $digit_id, then it's asking for $item_id, then $product_id... And in result I see Trying to get property of non-object in my view because actually relations is not chaining :(

@ztdan4ik
Copy link

ztdan4ik commented Jun 5, 2018

@GlyphDataServices

Shop
has Product[] Windows 8 and Windows 10
Windows 10 has ProductItem[] Windows 10 (two copies per order) and Windows 10 (one copy per order)
Windows 10 (two copies) has ProductDigit[] №1 (created by manager 1) and №2 (created by manager 2)
№1 has ProductDigitItem[] license code 1, license code 2, license code 3
№2 has ProductDigitItem[] license code 1, license code 2, license code 3

So,

Shops hasMany Product
each Product hasMany ProductItem
each ProductItem hasMany ProductDigit
each ProductItemDigit hasMany ProductDigitItem
each ProductDigitItem hasMany Orders

In back way it's always m2o, like you seen in my schema

I'll try wit aliases and give feedback here later

@machour machour modified the milestones: 2.0.16, 2.0.17 Jan 14, 2019
@samdark samdark removed this from the 2.0.17 milestone Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants