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

Issue with parent relations #60

Closed
psychonetic opened this issue Aug 26, 2017 · 8 comments
Closed

Issue with parent relations #60

psychonetic opened this issue Aug 26, 2017 · 8 comments
Assignees
Labels

Comments

@psychonetic
Copy link

First of all: great package!

I found an issue, if the model relates itself. Imagine you have a model Category, which references its parent category.

class Category extends Model
{

 public function parent() {
    	return $this->belongsTo('App\Category', 'parent_id', 'category_id');
 }

}

If you try to sort by parent.name or anything related to the parent category, it will fail, because both tables have the same name. But it can be fixed easily if one of the related tables would get an alias by default, when executing the join.

I may create a pull request.

By the way: Is the package still maintained?

@Kyslik
Copy link
Owner

Kyslik commented Aug 26, 2017

Any PRs are welcome :) and yes package is still maintained.

@Kyslik
Copy link
Owner

Kyslik commented Aug 28, 2017

@psychonetic any progress on creating PR?


I guess, best way to do this would be to detect self-referencing relationship and only use aliasing if detection returns true.

@Kyslik Kyslik self-assigned this Aug 28, 2017
@Kyslik Kyslik added the bug label Aug 28, 2017
@psychonetic
Copy link
Author

@Kyslik I wasn't at home during weekend. We open a pull request today :)

@Kyslik
Copy link
Owner

Kyslik commented Aug 28, 2017

@psychonetic see https://github.com/Kyslik/column-sortable/tree/fix/self-referencing-relationship

@psychonetic
Copy link
Author

@Kyslik Thanks, you are fast :) I will check that out and will edit this answer here.

@Kyslik
Copy link
Owner

Kyslik commented Aug 28, 2017

@psychonetic yea, I pushed it to 5.4 now; not tagged yet; so you can install it using specific hash

require: {
    "kyslik/column-sortable": "dev-L5.4#a43a5a53b8a1ebcd2eadad54689e61a9eeb15d15"
}

Please do test and report here :)

@Kyslik Kyslik reopened this Aug 28, 2017
@Kyslik Kyslik added the WIP label Aug 28, 2017
@psychonetic
Copy link
Author

@Kyslik Yep, I already did. It's working perfectly! So you can tag it.

@Kyslik
Copy link
Owner

Kyslik commented Aug 28, 2017

Done ;), 5.4.6

Thanks for reporting the bug.

Kyslik added a commit that referenced this issue Aug 28, 2017
@Kyslik Kyslik removed the WIP label Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants