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

One to Many "InTraverse" Class #249

Open
AddoSolutions opened this issue Apr 3, 2013 · 4 comments
Open

One to Many "InTraverse" Class #249

AddoSolutions opened this issue Apr 3, 2013 · 4 comments

Comments

@AddoSolutions
Copy link

Let's say I have a many to many relation from posts to comments. Right now if I executed:
<?php $post->comments
I would get an array of all of the comments associated with that post.

But here is what I propose (roughly):
<?php namespace \Orm\Model class InTraverse implements \ArrayAccess{ private $_elements = array(); function __get($prop){ $children = array(); foreach ($this->_elements as $id=>$element) $children[$id] = $element->$prop return $children; } }

And so on with methods etc.

This would allow us to:

<?php $post->comments->message
and would return an array with all the messages from each comment (which can easily be imploded, used for Form::select(), etc.)

@AddoSolutions
Copy link
Author

Sorry about all the updates, I accidentally submitted it before I could finish writing about the issue. This would still allow for current usage of the one to many (and many to many) functions, yet still adding a new later of flexibility to the ORM.

Thoughts?

@WanWizard
Copy link
Member

Code up a solution and we'll have a look... For now I don't see how this is going to work.

@emlynwest
Copy link
Contributor

This looks interesting, but I have used Arr:pluck() in the past to do this.

@AddoSolutions
Copy link
Author

Alright, I have coded up a potential solution. This basically causes all data returned by the ORM to be passed into a class in the Orm namespace in a model-level defined class called collection.

See: pull request #270

Commit: 3fcbdf2

Feel free to comment with any ideas and thoughts.

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

No branches or pull requests

3 participants