LazyRecord\BaseModel::getSchema PHP Method

getSchema() public method

public getSchema ( )
    public function getSchema()
    {
        if ($this->_schema) {
            return $this->_schema;
        } elseif (@constant('static::SCHEMA_PROXY_CLASS')) {
            // the SCHEMA_PROXY_CLASS is from the *Base.php file.
            if ($this->_schema = SchemaLoader::load(static::SCHEMA_PROXY_CLASS)) {
                return $this->_schema;
            }
            throw new Exception('Can not load ' . static::SCHEMA_PROXY_CLASS);
        }
        throw new RuntimeException('schema is not defined in ' . get_class($this));
    }

Usage Example

 /**
  * Build reference info from parent record.
  *
  * @param BaseModel $parentRecord
  * @param string $relationId
  * @return array
  */
 protected function buildRecordReferences(BaseModel $parentRecord, $relationId)
 {
     $parentSchema = $parentRecord->getSchema();
     $relationship = $parentSchema->getRelation($relationId);
     $refs = [];
     $refs[$relationship['foreign_column']] = ['record' => $parentRecord->toArray(), 'key' => $relationship['self_column'], 'referedRelationship' => $relationship->accessor];
     return $refs;
 }
All Usage Examples Of LazyRecord\BaseModel::getSchema