Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Improper results from Orm\Model::to_array() ?!
I'm extensively using the ORM now and ran across several issues (see also my pull requests on github). However, I'm wondering whether the following code is desired or not:
- line 1880: Shouldn't this line be within the foreach-loop? I get, what the line's for, but imho it should be doing the referencing on every related model, not just on the last one (as it currently does)
- line 1885: This one bugged me for quite a while. I had a many-to-one-to-one relation between a role, its permissions and the corresponding resources. Whenever I did a to_array() on the role, I would only get the first resource on the first permission. The later (in the array) permissions would only get an empty resource array. If I remove line 1885, it works perfectly and all my resources are mapped to their related permission within the role's 'permission'-indexed array.
Is it now just me not being used to the ORM, or is this (both reported bugs) incorrect behavior?
To start with your last question: all our projects run on 1.7/develop, and all of them use ORM. You just seem to bump into issues nobody has...
Line 1880 is a bracket, and line 1885 is an 'else' here, so you're not using the latest version. To prevent chasing ghosts, make sure you're on the latest version (i.e. 1.7/develop), and report issues on that version, so we're looking at the same bit of code.
I have an idea what you're talking about. It is not possible to reference each and every individual object. That was looked at and dismissed because too time and memory consuming.
So you can't dump A->B->A->B as it will stop when it encounters the same class name for a second time.
Ah crap, I'm always having hard times with fuel's branch naming conventions. And ya, you're right, I was looking at 1.6/master, not 1.7/develop. Hope I'll keep it in mind from now on to look at the most recent dev-branch.
But anyway, I see your point with too time and memory consuming recursive dumps. Yet I'm still wondering, whether the current code is - imho - correct. Have a look at this snippet
(dumped with 1.7/develop) and I really don't wanna bug anyone, but tell me, why there's no key "resource" on the 2nd and 3rd permissions-item even though there should be (the resources missing are "admin" and "site").
Probably because the recursion quick fix is rather buggy.
Feel free to come up with a better solution that prevents loops and doesn't run for hours...
Alright, I'll be giving it a try. Already got a solution on my mind, yet I'm not quite sure, if that'll be proper and sound. But we'll see
Also think about the memory implications of keeping track of everything.
Really you would like to have it dive into every related object it can find, but you want to prevent endless loops, that can occur if you have circular relations (like parent(1)->child(1)->parent(2)->child(1)).
I've looked into this in the past, but the only way to track this is to track all processed objects, and refuse to process an object a second time. Potentionally this can lead to a huge array you have to check...
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion