function testForceToLoadSomeLazyAttributes()
 {
     $object1 = $this->_createActiveRecord('Some annotation', 'Some content');
     $object2 = $this->_createActiveRecord('Some other annotation', 'Some other content');
     $query = lmbARQuery::create('LazyTestOneTableObject', $params = array('with_lazy_attributes' => array('annotation')));
     $arr = $query->fetch()->getArray();
     $this->assertTrue(array_key_exists('annotation', $arr[0]->exportRaw()));
     $this->assertFalse(array_key_exists('content', $arr[0]->exportRaw()));
     $this->assertTrue(array_key_exists('annotation', $arr[1]->exportRaw()));
     $this->assertFalse(array_key_exists('content', $arr[1]->exportRaw()));
 }
 static function createCoreARQueryForRelation($relation_info, $conn, $params = array())
 {
     $class = $relation_info['class'];
     $object = new $class();
     $table = $conn->quoteIdentifier($object->getTableName());
     $join_table = $conn->quoteIdentifier($relation_info['table']);
     $foreign_field = $conn->quoteIdentifier($relation_info['foreign_field']);
     $primary_field = $conn->quoteIdentifier($object->getPrimaryKeyName());
     $sql = "SELECT %fields% FROM {$table} INNER JOIN {$join_table} ON {$table}.{$primary_field} = {$join_table}.{$foreign_field}" . " %tables% %left_join% %where% %group% %having% %order%";
     $query = lmbARQuery::create($class, $params, $conn, $sql);
     $fields = $object->getDbTable()->getColumnsForSelect();
     foreach ($fields as $field => $alias) {
         $query->addField($field, $alias);
     }
     return $query;
 }
Пример #3
0
 /**
  *  Finds a collection of records(not lmbActiveRecord objects!) from database table
  *  @param string|object filtering criteria
  *  @param array sort params
  *  @return iterator
  */
 function findAllRecords($criteria = null, $sort_params = array())
 {
     $query = lmbARQuery::create(get_class($this), $params = array('criteria' => $criteria, 'sort' => $sort_params), $this->_db_conn);
     return $query->fetch($decorate = false);
 }
Пример #4
0
 function testGroup()
 {
     $course1 = $this->creator->createCourse();
     $lecture1 = $this->creator->createLecture($course1);
     $lecture2 = $this->creator->createLecture($course1);
     $course2 = $this->creator->createCourse();
     $lecture3 = $this->creator->createLecture($course2);
     $lecture4 = $this->creator->createLecture($course2);
     $query = lmbARQuery::create('LectureForTest', array('group' => 'course.id'), $this->conn);
     $rs = $query->eagerJoin('course')->fetch();
     $this->assertEqual($rs->count(), 2);
     $arr = $rs->getArray();
     $this->assertEqual(count($arr), 2);
     $this->assertEqual($arr[0]->getTitle(), $lecture1->getTitle());
     $this->assertEqual($arr[1]->getTitle(), $lecture3->getTitle());
 }
Пример #5
0
 /**
  * @param string|object $class_name_or_obj
  * @param array $params
  * @param lmbDbConnection $conn
  * @param string $sql
  * @return lmbARQuery
  */
 static function create($class_name_or_obj, $params = array(), $conn = null, $sql = '')
 {
     if (!$conn) {
         $conn = lmbToolkit::instance()->getDefaultDbConnection();
     }
     if (!is_object($class_name_or_obj)) {
         $class_name_or_obj = new $class_name_or_obj();
     }
     $query = new lmbARQuery($class_name_or_obj, $conn, $sql, $params);
     if (isset($params['criteria']) && $params['criteria']) {
         $criteria = lmbSQLCriteria::objectify($params['criteria']);
     } else {
         $criteria = lmbSQLCriteria::create();
     }
     $has_class_criteria = false;
     if (isset($params['class'])) {
         $filter_object = new $params['class']();
         $criteria = $filter_object->addClassCriteria($criteria);
         $has_class_criteria = true;
     }
     if (!$has_class_criteria) {
         $criteria = $class_name_or_obj->addClassCriteria($criteria);
     }
     $query->where($criteria);
     $sort_params = isset($params['sort']) && $params['sort'] ? $params['sort'] : $class_name_or_obj->getDefaultSortParams();
     $query->order($sort_params);
     if (isset($params['group']) && $params['group']) {
         $query->group($params['group']);
     }
     $join = isset($params['join']) && $params['join'] ? $params['join'] : array();
     if (!is_array($join)) {
         $join = explode(',', $join);
     }
     foreach ($join as $relation_name => $params_or_relation_name) {
         if (is_numeric($relation_name)) {
             $query->eagerJoin(trim($params_or_relation_name));
         } else {
             $query->eagerJoin(trim($relation_name), $params_or_relation_name);
         }
     }
     $attach = isset($params['attach']) && $params['attach'] ? $params['attach'] : array();
     if (!is_array($attach)) {
         $attach = explode(',', $attach);
     }
     foreach ($attach as $relation_name => $params_or_relation_name) {
         if (is_numeric($relation_name)) {
             $query->eagerAttach(trim($params_or_relation_name));
         } else {
             $query->eagerAttach(trim($relation_name), $params_or_relation_name);
         }
     }
     return $query;
 }
 static function createCoreARQueryForRelation($relation_info, $conn, $params = array())
 {
     return lmbARQuery::create($relation_info['class'], $params, $conn);
 }