diff --git a/lib/Doctrine/Resource/Table.php b/lib/Doctrine/Resource/Table.php new file mode 100644 index 000000000..c82ef56be --- /dev/null +++ b/lib/Doctrine/Resource/Table.php @@ -0,0 +1,64 @@ +. + */ + +/** + * Doctrine_Resource_Table + * + * @author Konsta Vesterinen + * @author Jonathan H. Wage + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version $Revision$ + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + */ +class Doctrine_Resource_Table +{ + protected $_model = null; + + public function __construct($model) + { + $this->_model = $model; + } + + public function find($pk) + { + $model = $this->_model; + + $record = new $model(); + + $pk = is_array($pk) ? $pk:array($pk); + $identifier = $record->identifier(); + $identifier = is_array($identifier) ? $identifier:array($identifier); + + $where = ''; + foreach (array_keys($identifier) as $key => $name) { + $value = $pk[$key]; + $where .= $model.'.' . $name . ' = '.$value; + } + + $query = new Doctrine_Resource_Query(); + $query->from($model)->where($where)->limit(1); + + return $query->execute()->getFirst(); + } +} \ No newline at end of file