can we use recurcive relationship for BelongsToManyJson relations?
Closed this issue · 3 comments
Hello, mr. Staudenmeir!
Thank you for your great packages!
The question is as simple as a title. I have BelongsToManyJson
relationship in a model. It has parent_ids
json field in this model. And I need to fetch all descendant entries. I see at the docs related tables need single related columns like 'parent_id' and there's no sign of using a json column as a related one.
And maybe is there a way to use it or at least you think to add this feature in the future?
Hi @bigkase,
This is not possible, but I'll look into it.
It would be possible to implement that but a lot of work. Nothing I can provide anytime soon.
Can you still change your database schema or is it set in stone? I'm asking because you're looking for graph relationships where a model can have multiple parents. The package does support that but only with a pivot table:
https://github.com/staudenmeir/laravel-adjacency-list?tab=readme-ov-file#graphs-multiple-parents-per-node-many-to-many
Ideally, you could change your database schema to match this structure.
If you can't do that, a possible (but not very elegant) workaround would be this:
- You keep the
parent_ids
column but also add a pivot table. - Everytime the value of
parent_ids
changes, you sync these changes with pivot table. - This way, you could use the package's graph relationships.
Hello,
Sorry I lost this message.
Thank you for your advises! I think I was just curios about this feature in the package. I'll try this additionally now I don't need these.
Thank you again!