Created
May 2, 2012 14:36
-
-
Save zombor/2576998 to your computer and use it in GitHub Desktop.
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
| diff --git a/classes/automodeler/gateway/database/orm.php b/classes/automodeler/gateway/database/orm.php | |
| new file mode 100644 | |
| index 0000000..0d6c8fb | |
| --- /dev/null | |
| +++ b/classes/automodeler/gateway/database/orm.php | |
| @@ -0,0 +1,36 @@ | |
| +<?php | |
| + | |
| +class AutoModeler_Gateway_Database_ORM extends AutoModeler_Gateway_Database | |
| +{ | |
| + public function find_related( | |
| + $key, | |
| + AutoModeler_Model $source_model, | |
| + Database_Query_Builder_Select $qb = NULL | |
| + ) | |
| + { | |
| + $model = 'Model_'.inflector::singular($key); | |
| + $temp = new $model(); | |
| + | |
| + if ( ! $query) | |
| + { | |
| + $qb = db::select_array($temp->fields()); | |
| + } | |
| + | |
| + $related_table = $temp->gateway()->table_name(); | |
| + $join_table = $this->_table_name.'_'.$related_table; | |
| + $this_key = inflector::singular($this->_table_name).'_id'; | |
| + $f_key = inflector_singular($related_table).'_id'; | |
| + | |
| + $query = $qb->from($related_table) | |
| + ->join($join_table) | |
| + ->on($join_table.'.'.$f_key, '=', $related_table.'.id') | |
| + ->where($join_table.'.'.$this_key, '=', $source_model->id) | |
| + return $temp->gateway()->load_set($query) | |
| + } | |
| + | |
| + // Should this do 1:n as well as n:n? | |
| + public function find_parent($related, AutoModeler_Model $source_model) | |
| + { | |
| + | |
| + } | |
| +} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment