Created
October 1, 2011 09:55
-
-
Save jamierumbelow/1255824 to your computer and use it in GitHub Desktop.
A simple concept for basic JOIN/relationship support in MY_Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Customer extends MY_Model { | |
protected $relations = array( | |
'addresses' => array( | |
'join_on' => 'addressable_id', | |
'where' => array('addresses.addressable_type' => 'customers') | |
) | |
); | |
} | |
// This... | |
$this->db->select('customers.*, addresses.*')->join('addresses', 'addresses.addressable_id = customers.id')->where('addresses.addressable_type', 'customers')->get(); | |
// ...becomes this. | |
$this->customer->with_relation('addresses')->get_all(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends MY_Model { | |
protected $relations = array( | |
'books' => 'id' | |
); | |
} | |
// This... | |
$this->db->select('users.*, books.*')->join('books', 'books.id = users.id')->get(); | |
// ...becomes this. | |
$this->user->with_relation('books')->get_all(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment