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
Example of tables structure #3
Comments
Hi, parrker! I have just written an example of migrations. Let me know if something is unclear. |
Hi franzose, the migrations were really helpful! Thanks! Now I have a different problem (probably because I'm not too experienced with both Laravel and the idea of closure tables). How should I go about saving nodes in the tree? I create a new element like this:
Is this the right way? I can see that data is stored in both my tables successfully, but the
I have a feeling I am doing it wrong. |
Hi, parrker) First of all, please, show me what data containts your products' categories table and tree paths one now. Then, if possible, SQL logs. I'm not able to test them at the time. |
These are my migrations for creating tables:
As you see, I don't have any real data yet, I'll use a separate table for lang data. And the code I was trying to run is this:
|
Please, look at the closuretable.php file now around 197 and 207 lines. I changed the code slightly. Now it tries to convert a given object to array. As I know DB::query method returns either stdClass or array according to the configuration you set. And it returns stdClass by default. So, there was no conversion from stdClass to array that led to wrong argument type error. Please, try updated code and let me know either about your or about some new errors. Thank you very much. |
I have tried the updated version, and the fulltree() method works fine now. Thanks! But now I noticed that there is an error when I try to insert a child into an existing node. I tried the following:
For the first and second way I get the following error:
For the third I get this:
Sorry to keep bothering you about this, but I want to make my trees work via closure tables so much! |
Hi, parrker. I apologize for the delay. I have tested ClosureTable for the issues you mentioned and fixed the latter one in treepath.php. What is the version of PHP you are using? I cannot reproduce class scope error on 5.4.11... |
I really feel ashamed in front of those almost 120 people who have downloaded the bundle full of bugs :( Thanks for your help, parrker ;) |
Parrker, trouble with class scope may happen due to the fact that there are static calls from the closure. I mean 'descendants' and 'ancestors' methods. There are joins which use closure to define additional join rules. See 133-134 and 147-148 line in closuretable.php. |
Please, try to change 'static::' calls to 'ClosureTable::' in joins' closures of those methods ('ancestors' and 'descendants') and let me know about the results. |
Hi franzose! For a moment I thought you forgot about me and this bundle :) After updating the Treepath class, the third way of assigning child to a node (using the P.S. I am using PHP 5.3.17 at the moment. I know that we will have PHP 5.3 on my live web server for some time, so I cannot upgrade :( |
Now I encountered another issue: because we changed the I spent some time researching, and this is the solution that I used in the end:
The issue was with the closure's scope. Apparently, in PHP 5.4 you don't have to add |
Hey, it seems that I have found an answer. It's quirky now, but we can define join rules first and then pass them to the closure. So, instead of
we will have this:
It's a bit quirky, but we now prepare values first. |
Oh, I edited my comment without refreshing the page :) My solution is similar, I just pass the class name to closure instead of variables. Yours looks neater, I think. |
From the beginning the purpose was to create a plug-and-play thing. Try my version, if it works appropriately, I will submit changes :) |
Wait, in the ancestors method you still have one static call:
|
Ooops, it's a mistake. Now it should be just |
One more thing, some of your joins lost the "not equals" operator:
|
May be parser ate them... |
I have updated closuretable.php with this quick fix. Try it. Later I'll solve this issue in more suitable way. |
I have another one. I cannot grab the node's ancestors for some reason. The descendants are returned correctly. |
Sorry, parrker, but from 8 till 31 of May I will be unable to maintain the project (and fix all the bugs) due to the trip with my music band... Thank you for forking it ;) |
I am not too sure if I get the fork to work, but it's worth a shot. Good luck on the tour! |
Hi, parrker. I'm able to work again. See and try my fixes! Now 'ancestors' returns what it should, 'descendants' returns all descendants (not only immediate children). And I added 'children' method to get those immediate fucking children :))) After all that fixin' I had a thought that it was all quite simple to fix and I don't know now why I missed all that before. Now I will think about your suggestion about 'fulltree' method. I suppose it's not that difficult to implement... |
Hi, I have never used closure tables before, and I am considering to use your class in my new Laravel project. I am a bit confused about which columns must be in each of my tables. Could you provide an example migration, please?
The text was updated successfully, but these errors were encountered: