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

ltree relationships #81

Open
boris-glumpler opened this issue May 10, 2024 · 4 comments
Open

ltree relationships #81

boris-glumpler opened this issue May 10, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@boris-glumpler
Copy link

boris-glumpler commented May 10, 2024

Just wondering out loud here, but would it be within the scope of this package to add relationships based on an ltree column? So something like children, parent and ancestors. Maybe even to a given depth?

I've just used ltree for a comments system and ended up doing two queries. The first one gets a paginator just for the first level and the second one gets any children for the items in that paginator. I then have a tree class that builds up the hierarchy, sorts it properly and sets the resulting collection back on the paginator. It'll work just fine for my use case as there won't be many comments at all and even less nested ones, but it got me wondering if this couldn't be solved more efficiently.

@tpetry
Copy link
Owner

tpetry commented May 10, 2024

Hmm, I‘ve not implemented a custom relationship class yet. But it could work. I think I could have a look at non-ltree tree relationship implementations.

I guess then also a model cast would make sense. But in what should it be casted? An object that splits the parts in array elements?

@boris-glumpler
Copy link
Author

I haven't either. I googled for a bit and found this repo, but it does way too much for my liking, tbh: https://github.com/umbrellio/laravel-ltree

I'm not sure what you mean with the model cast? Like a tree collection? The way I handled it was add a regular children property to my comment model (that was all I needed) and then just populated those within my tree builder. Doesn't seem very laravely, tbh ;)

@tpetry
Copy link
Owner

tpetry commented May 20, 2024

So you're only interested in the BelongsToAncestorsTree and BelongsToDescendantsTree relationships from that package? Nothing more? I think at least scopes are also needed.

Its a nice idea. But I probably don't have the time for it currently. I've never implemented a relationship. So it needs a lot of fiddling around to find out how it works.

@tpetry tpetry added the enhancement New feature or request label May 20, 2024
@boris-glumpler
Copy link
Author

Yup, scopes do make sense.

Don't worry about working on it for now 😉 What I have works for my current project just fine and should it turn out later to not be enough, then I might give it a go myself at a later date.

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

No branches or pull requests

2 participants