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

[9.0] Add support for self join relationships. #2051

Merged
merged 10 commits into from
Apr 24, 2019
Merged

[9.0] Add support for self join relationships. #2051

merged 10 commits into from
Apr 24, 2019

Conversation

Morinohtar
Copy link
Contributor

A fix for the issue #2045 . It only addresses the "BelongsTo". I did not touch the rest of the relations, so a more complete "fix" can be made.

I also replaced the deprecated function "assertContains" with "assertStringContainsString" in the QueryDataTableTest.

I ran the tests and nothing exploded :P

@Morinohtar Morinohtar changed the title Sorting nested relation that refer to the same table. [9.0] Sorting nested relation that refer to the same table. Apr 10, 2019
@Morinohtar Morinohtar changed the title [9.0] Sorting nested relation that refer to the same table. [9.0] Sorting nested relation that refers to the same table. Apr 10, 2019
Copy link
Owner

@yajra yajra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good with some DB compatibility issues. Will try to test this on actual project and get back to this as soon as I can. Thanks!

@@ -169,19 +169,23 @@ protected function joinEagerLoadedColumn($relation, $relationColumn)

case $model instanceof BelongsTo:
$table = $model->getRelated()->getTable();
$alias = "alias_{$index}_{$table}";
$tableAs = "{$table} AS $alias";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break some installations with Oracle database. Please use "{$table} $alias" removing the AS from query.

Copy link
Contributor Author

@Morinohtar Morinohtar Apr 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if i remove the AS then MySQL won't work... ok, i managed something, update coming soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run your tests again now?

Copy link
Owner

@yajra yajra Apr 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but your previous PR version is much better. AFAIK, it should work on MySQL since that is one of the reasons why I created this package version to work on Oracle.

On the other hand, I think I already created a patch that properly translates Oracle AS query. Will review with my other package https://github.com/yajra/laravel-oci8 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what now? You want the first one again?

@@ -38,6 +45,9 @@ public function __construct($model)
parent::__construct($builder->getQuery());

$this->query = $builder;

$connection = config('database.default');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are cases where the connection is set from the model or via runtime using query. This is will not work on those situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure. But in your earlier reply (#2051 (comment)) you said, basically, this wouldnt even be necessary. So, what now?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so please revert the commits to 1st one you sent. Might be able to test this within the week. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. Sorry for the mess with the commits.

@yajra yajra merged commit f5e9438 into yajra:9.0 Apr 24, 2019
@yajra yajra changed the title [9.0] Sorting nested relation that refers to the same table. [9.0] Add support for self join relationships. Apr 24, 2019
@yajra
Copy link
Owner

yajra commented Apr 24, 2019

This also fixes a lot of issues: [#2045], [#2054], [#2024], [#1977], [#880], [#577], [#522], etc.

Thanks a lot 🚀 released on v9.1.0 🍻

@amrmahrous
Copy link

please consider the soft delete , the new release cause an error "cloumn related_table.deleted_at not fount in where clause" however it shall be related_table_0_deleted_at

I rollback back to 9.0.1 and it works just perfect .

thank you for the great work , this project helps me a lot making fast delevlopment !

@yajra
Copy link
Owner

yajra commented Apr 26, 2019

Reverting due to unseen breaking change on soft deletes.

Related issue: #2058

yajra added a commit that referenced this pull request Apr 26, 2019
@yajra yajra mentioned this pull request Apr 26, 2019
yajra added a commit that referenced this pull request Apr 26, 2019
@thomaswalker-dev
Copy link

Any news on this?

@Morinohtar
Copy link
Contributor Author

@yajra is this issue already addressed in the latest version or is it still going on?

@carferdas
Copy link

This fix not working

@moeezs82
Copy link

moeezs82 commented Nov 22, 2022

public function query(Jobseeker $model): QueryBuilder
{
return $model->applyScopes($model->newQuery()->with([
'cv:id,jobseeker_id,name',
'jobseeker_ques_opt.options',
]))->latest();
}

//this is the parameter i'm passing for column search
->parameters([
'initComplete' => "function () {
this.api().columns().every(function () {
var column = this;
var input = document.createElement("input");
$(input).appendTo($(column.footer()).empty())
.on('keyup change', function(){
column.search($(this).val(), false, false, true).draw();
})
});
}"
])

this is my query for datatable it is working perfect but search is not working on relational data

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.

6 participants