phproad / phpr-framework

[PHPR Framework] PHPRoad system files
http://phproad.com
MIT License
12 stars 2 forks source link

Add eager loading to Db_ActiveRecord #5

Closed daftspunk closed 8 years ago

daftspunk commented 11 years ago

The PHPR AR is pretty solid, except it doesn't support eager loading.

Syntax would be like this:

User::create()->find_all(null, array('friends'));

Resulting in a grouped SQL statement to populate the "friends" relationship

SELECT * FROM user_friends WHERE id IN (1, 2, 3, 4, 5)

The result is a collection of eager assosiated that can be used when $user->friends is called. At the moment the code would produce:

SELECT * FROM user_friends WHERE id = 1;
SELECT * FROM user_friends WHERE id = 2;
SELECT * FROM user_friends WHERE id = 3;
SELECT * FROM user_friends WHERE id = 4;
SELECT * FROM user_friends WHERE id = 5;

^ Yuck!

highruned commented 11 years ago

:+1: