public function getInfo() { if (!$this->owner) { $remoteTableName = DbObject::_getTableName($this->remoteClassName); $sql = "select * from {$remoteTableName} where {$this->remoteFieldName} = :id:int"; $row = $this->dbObject->getDb()->fetchRow($sql, array($this->remoteFieldName => $this->dbObject->getField($this->localFieldName))); $this->owner = new $this->remoteClassName($row); } return $this->owner; }
public function getInfo() { if (!$this->theOneIsSet) { $remoteTableName = DbObject::_getTableName($this->remoteClassName); $sql = "select * from {$remoteTableName} where {$this->remoteFieldName} = :id:int"; $row = SqlFetchRow($sql, array('id' => $this->dbObject->getField($this->localFieldName))); if ($row) { $this->theOne = new $this->remoteClassName($row); } $this->theOneIsSet = 1; } return $this->theOne; }
public function getInfo() { if (!$this->theMany) { $remoteTable = DbObject::_getTableName($this->remoteClass); $sql = "select * from {$remoteTable} \n\t\t\t\t\tinner join {$this->joinTable} on {$this->joinTable}.{$this->joinTableRemoteField} = {$remoteTable}.{$this->remoteField}\n\t\t\t\t\twhere {$this->joinTable}.{$this->joinTableLocalField} = :id:int"; $rows = SqlFetchRows($sql, array('id' => $this->dbObject->getScalar($this->localField))); $this->theMany = array(); foreach ($rows as $thisRow) { $this->theMany[] = new $className($thisRow); } } return $this->theMany; }
public function getInfo() { if (!$this->theMany) { $params = array(); $params['orderby'] = $this->params['orderBy']; $remoteTableName = DbObject::_getTableName($this->remoteClassName); $conditions = $this->params['conditions']; $conditions[$this->remoteFieldName] = $this->dbObject->getField($this->localFieldName); $selectInfo = DbConnection::generateSelectInfo($remoteTableName, '*', $conditions, $params); $rows = $this->dbObject->getDb()->fetchRows($selectInfo['sql'], $selectInfo['params']); $this->theMany = array(); foreach ($rows as $thisRow) { if ($this->params['mapField']) { $this->theMany[$thisRow[$this->params['mapField']]] = new $this->remoteClassName($thisRow); } else { $this->theMany[] = new $this->remoteClassName($thisRow); } } } return $this; }
/** * Retrieves a DbObject from the given table with a row in it, creating the row if neccesary * * @param string $className name of the DbObject class to return an instance of * @param assoc_array $conditions $field => $value for generating the where clause to * @return DbObject */ public static function _getOne($className, $conditions = NULL, $default = NULL) { $tableName = DbObject::_getTableName($className); $row = self::_getConnection($className)->selsertRow($tableName, "*", $conditions, $default); return new $className($row); }