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

Model_Nestedset dump_tree() relations #301

Closed
sagikazarmark opened this issue Sep 18, 2013 · 10 comments
Closed

Model_Nestedset dump_tree() relations #301

sagikazarmark opened this issue Sep 18, 2013 · 10 comments

Comments

@sagikazarmark
Copy link
Contributor

Model_Nestedset does not load relations or EAV.

It loads relation in the root element, but not in the children.

Relations are not dumped when dumping into multi-dimensional array.

@sagikazarmark
Copy link
Contributor Author

Hm. It looks like that this works when the magic get method always returns a reference and as_object is true, even if the property does not exists. EAV still does not work.

@sagikazarmark
Copy link
Contributor Author

OK. This issue is in connection with #300 which has been solved I think.

@sagikazarmark
Copy link
Contributor Author

Here is the status: I reopen this issue, because the relations are NOT set for children when using dump_tree().
It seemed to be working because the $children and $path attributes were set EAV way, so the relation was set, but it is fixed now.

So the problem: relations are only set for the root node and not for all.

@sagikazarmark
Copy link
Contributor Author

Actually this issue is true for all collection methods. (The dump_tree uses them too).

So these collection methods should have an argument for having the same relations loaded as the parent.

$model->descendants(true)->get(); means, that all the descendants will have the same relations as the parent,

Another option is to have a relate() function on Model_Nestedset, which modifies the _node_operation and inserts a relation index with the desired relations as an array. ($model->descendants(true)->get(); should do the same, but that is shorter for the same relations).

I started to test it out, but I am waiting for your response about it.

@sagikazarmark
Copy link
Contributor Author

@stevewest can you check this out?

@emlynwest
Copy link
Contributor

@sagikazarmark I do not know anything about the implementation of nested sets. We all have full time jobs as well as working on fuel so have a little patience 😄

@sagikazarmark
Copy link
Contributor Author

OK 😄

@WanWizard
Copy link
Member

There is no support for relations whatsoever when using nested sets, all methods operate on the current model only. dump_tree() operates on a nested set model instance, which will be used as root of the nested sets tree.

I think adding logic to figure out which relations the root node had loaded, and then fetch these for all other nodes too might potentionally be a bad idea, I may have a lot, some may be lazy loaded, etc.

@sagikazarmark
Copy link
Contributor Author

The actual use case is a menu model using EAV to be able to define custom attributes, so when editing a menu item you definitely can use a relation as you are operating on one model. The same for adding end deleting.

The only problem is dump.

Maybe I could define columns for the model without EAV, but using EAV for this would be cool. 😄

But I absolutely understand your point, and thought this might be a bad idea, so I this is why I suggested to set the required relation in the collection method ($model->descendants()->relate('Relation1')->get()). This way mixing lazy loaded and not lazy loaded relations is not a problem.

I don't think using relations with nested sets is a problem. Why do you think it is?

@WanWizard
Copy link
Member

I don't think it is. The issue that I have is that if the model has 10 related models, and the root has 8 of them fetched, and your tree contains 200 nodes, automatically fetch all related objects the root has loaded will cause at least 1600 objects to be created when you dump the tree, and potentionally a lot more if they are "many" relations.

I'll add support for related(), using same syntax as on a normal model query, so you can do what you have suggested.

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

No branches or pull requests

3 participants