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

It would be super if ORM didn't actually run a query until the last minute #4

Open
Altreus opened this issue Aug 22, 2013 · 0 comments

Comments

@Altreus
Copy link

Altreus commented Aug 22, 2013

It's often necessary to filter a result. In ORM you have the option of doing a find() or accessing a relation on an object, in which case you get results immediately, or writing your own methods or using query() to create a custom search.

The structure of ORM at the moment, however, means that the first examples could easily return the same type of object as query() does - one on which you can then run further methods.

e.g.

$posts = Model_Blog::find(1)->posts;  // array
$recent_posts = Model_Blog::find(1)->posts->where('posted', '>', \DB::expr('NOW() - INTERVAL 1 WEEK');  // can't do this

You can do this -

$recent_posts = Model_Blog::query()
    ->where('id', 1)
    ->related('posts')
    ->where('posted', '>', \DB::expr('NOW() - INTERVAL 1 WEEK');
  • but this defeats the point of using ORM in the first place.

Further, you could then do

$recent_posts->get();

Like you already do, but if you did

foreach ($recent_posts as $id => $post)

it would do it for you. That is to say, an ORM Query object could be iterable by running it and iterating the result.

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

1 participant