Пример #1
0
 /**
  * Returns an array of owned objects.
  *
  * @param string $model   Name of the model.
  * @param aray   $options Optional relation options.
  *
  * @return array
  */
 public function hasMany($model, $options = [])
 {
     $options = static::getRelationInfo($model, $options);
     if (!isset($options['localKey'])) {
         $options['localKey'] = 'id';
     }
     if (!isset($options['foreignKey'])) {
         $options['foreignKey'] = Inflector::foreignKey(static::tableName(false));
     }
     return $options['model']::select()->where("{$options['foreignKey']} = :foreignKey")->setParameter('foreignKey', $this->{$options['localKey']})->mergeNextWhere();
 }