/framework/core/db/DbRelationshipHasOne.php

http://zoop.googlecode.com/ · PHP · 22 lines · 19 code · 3 blank · 0 comment · 2 complexity · bfae1d597824648c2fbec1d222e26d2c MD5 · raw file

  1. <?php
  2. class DbRelationshipHasOne extends DbRelationshipBasic
  3. {
  4. private $theOne;
  5. private $theOneIsSet;
  6. public function getInfo()
  7. {
  8. if(!$this->theOneIsSet)
  9. {
  10. $remoteTableName = DbObject::_getTableName($this->remoteClassName);
  11. $sql = "select * from $remoteTableName where {$this->remoteFieldName} = :id:int";
  12. $row = SqlFetchRow($sql, array('id' => $this->dbObject->getField($this->localFieldName)));
  13. if($row)
  14. $this->theOne = new $this->remoteClassName($row);
  15. $this->theOneIsSet = 1;
  16. }
  17. return $this->theOne;
  18. }
  19. }