Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM suggestion
  • I was working with the ORM package and found there's no way to do further filtering on the related model.
    Thus say, in a post / comments scenario, using $post->comments (lazy loading) you receive the full list of comments for a post without the posibility of sorting / filtering.
    Neither you can use things like 'as array'.
    This is because the ORM relation classes returns a result. I think ORM returning the query object is better, as writing $post->comments->get() is not such a big deal and also you are able to do things like $post->comments->where(...)->order_by(...), etc. Just a suggestion.
    Best regards.
  • It's always smart to look into the issues on Github: https://github.com/fuel/orm/issues (this is partially already planned) Also if you make suggestions on the forums: don't count on any of us remembering, I don't plan or decide based on the forums. That's what the issue tracker is for. The forums or for support and discussion. Lazy loading will never support where conditions (unless like the top example https://github.com/fuel/orm/issues/3 ), that's just not how lazy-loading can or should work. as_array() is always available, but only on individual objects. Last but not least:
    This is because the ORM relation classes returns a result. I think ORM returning the query object is better, as writing $post->comments->get() is not such a big deal and also you are able to do things like $post->comments->where(...)->order_by(...), etc.
    It's lazy loading, which means load on demand as if it's there. What your suggesting is just loading it and dropping lazy loading: won't happen.
  • Jelmer, thanks for your quick response
    It's always smart to look into the issues on Github: https://github.com/fuel/orm/issues (this is partially already planned)
    Sorry, I'm really a newbie on this community driven code development. Hope I'll learn fast enough and bother you the less as possible.
    Also if you make suggestions on the forums: don't count on any of us remembering, I don't plan or decide based on the forums. That's what the issue tracker is for. The forums or for support and discussion.
    My intention was, at this point, to know what other people think about this, and in case the suggestion was well received, to submit my already modified version of the ORM package which supports the features I suggest.
    I thought that hearing the community first will spare you from another request that perhaps nobody really wants or it's mistaken (as apparently you are telling me), and spare me, of course, of doing a request on the orm package, writing a Test Unit, pulling a request on the docs, etc.
    It's lazy loading, which means load on demand as if it's there. What your suggesting is just loading it and dropping lazy loading: won't happen.
    I'm sorry, probably my english is not good enough, but I'm really missing the point of what you are trying to say. As I can read on https://github.com/fuel/orm/issues/3, you are proposing conditions to be enabled on the eager loading, but no on the lazy one. It's not just a case of 'when' are you doing the request to the database?
    The way you are exposing this makes me think you have other aspect in mind, but I can't really figure it out.
    I really want to understand your point of view, so if you I'll be very glad if you take the time to expose it further. Best regards.
  • When you lazy-load you use the property as if it's already there, that means you can't query it in the process. Lazy loading is a quick shortcut, for real querying you use the eager loading. What you're proposing is a very-very bad idea: if I eager load a relation and I use $model->rel I get an array or the related object. When I would lazy load it with your way I would get a query object. That's very inconistent and bad behavior. If you want to query: query eager loaded, otherwise accept that there's limitations.
  • Jelmer, thanks for your response. I see your point now, and you are totally right.
    I came across this same issue and think in something like
    $post->comments // returns a comments object
    $post->comments() // returns a query object
    
    but I dropped, because it remaind me some things I don't like of Symphony. I know we have to deal with limitations, but I think rethinking the limits it's a good exercise. In some way, I think Fuel was founded because of the limits Expression Engine imposed to CI development. Said that, what about something like:
    $post->relation('comments')->where()->order_by // add conditions to the comment search
    $post->comments // behaves as always
    

    Thanks again for taking your time in answer. I've really learn a lot in the last week reading the Fuel code and exchanging ideas with you.
    Best regards.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion