예제 #1
0
파일: record.php 프로젝트: OpenBX/obx.core
 /**
  * @param Entity $entity
  * @param int|string|null|Entity $id
  * @param null $select
  * @param bool $lazyLoad
  * @throws Err
  */
 public function __construct(Entity $entity, $id = null, $select = null, $lazyLoad = self::DEF_LAZY_LOAD)
 {
     if (!$entity instanceof Entity) {
         throw new Err('', Err::E_RECORD_ENTITY_NOT_SET);
     }
     $this->entity = $entity;
     $this->primaryKey = $this->entity->getMainTablePrimaryKey();
     $this->primaryKeyAutoIncrement = $this->entity->getMainTableAutoIncrement();
     if (empty($select) || !is_array($select)) {
         $this->entityFields = array_keys($this->entity->getTableFieldsCheck());
     } else {
         $this->entityFields = array();
         $arRealTableFields = $this->entity->getTableFields();
         foreach ($select as &$field) {
             if (!array_key_exists($field, $arRealTableFields)) {
                 $this->entityFields[] = $field;
             }
         }
     }
     $this->MessagePool = $this->entity->getMessagePool();
     if (null !== $id) {
         $this->read($id, $select);
     }
     $this->lazyLoad = !!$lazyLoad;
 }