選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ActiveQueryInterface.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db;
  8. /**
  9. * ActiveQueryInterface defines the common interface to be implemented by active record query classes.
  10. *
  11. * That are methods for either normal queries that return active records but also relational queries
  12. * in which the query represents a relation between two active record classes and will return related
  13. * records only.
  14. *
  15. * A class implementing this interface should also use [[ActiveQueryTrait]] and [[ActiveRelationTrait]].
  16. *
  17. * @author Qiang Xue <qiang.xue@gmail.com>
  18. * @author Carsten Brandt <mail@cebe.cc>
  19. * @since 2.0
  20. */
  21. interface ActiveQueryInterface extends QueryInterface
  22. {
  23. /**
  24. * Sets the [[asArray]] property.
  25. * @param boolean $value whether to return the query results in terms of arrays instead of Active Records.
  26. * @return $this the query object itself
  27. */
  28. public function asArray($value = true);
  29. /**
  30. * Executes query and returns a single row of result.
  31. * @param Connection $db the DB connection used to create the DB command.
  32. * If `null`, the DB connection returned by [[modelClass]] will be used.
  33. * @return ActiveRecordInterface|array|null a single row of query result. Depending on the setting of [[asArray]],
  34. * the query result may be either an array or an ActiveRecord object. `null` will be returned
  35. * if the query results in nothing.
  36. */
  37. public function one($db = null);
  38. /**
  39. * Sets the [[indexBy]] property.
  40. * @param string|callable $column the name of the column by which the query results should be indexed by.
  41. * This can also be a callable (e.g. anonymous function) that returns the index value based on the given
  42. * row or model data. The signature of the callable should be:
  43. *
  44. * ```php
  45. * // $model is an AR instance when `asArray` is false,
  46. * // or an array of column values when `asArray` is true.
  47. * function ($model)
  48. * {
  49. * // return the index value corresponding to $model
  50. * }
  51. * ```
  52. *
  53. * @return $this the query object itself
  54. */
  55. public function indexBy($column);
  56. /**
  57. * Specifies the relations with which this query should be performed.
  58. *
  59. * The parameters to this method can be either one or multiple strings, or a single array
  60. * of relation names and the optional callbacks to customize the relations.
  61. *
  62. * A relation name can refer to a relation defined in [[ActiveQueryTrait::modelClass|modelClass]]
  63. * or a sub-relation that stands for a relation of a related record.
  64. * For example, `orders.address` means the `address` relation defined
  65. * in the model class corresponding to the `orders` relation.
  66. *
  67. * The following are some usage examples:
  68. *
  69. * ```php
  70. * // find customers together with their orders and country
  71. * Customer::find()->with('orders', 'country')->all();
  72. * // find customers together with their orders and the orders' shipping address
  73. * Customer::find()->with('orders.address')->all();
  74. * // find customers together with their country and orders of status 1
  75. * Customer::find()->with([
  76. * 'orders' => function (\yii\db\ActiveQuery $query) {
  77. * $query->andWhere('status = 1');
  78. * },
  79. * 'country',
  80. * ])->all();
  81. * ```
  82. *
  83. * @return $this the query object itself
  84. */
  85. public function with();
  86. /**
  87. * Specifies the relation associated with the junction table for use in relational query.
  88. * @param string $relationName the relation name. This refers to a relation declared in the [[ActiveRelationTrait::primaryModel|primaryModel]] of the relation.
  89. * @param callable $callable a PHP callback for customizing the relation associated with the junction table.
  90. * Its signature should be `function($query)`, where `$query` is the query to be customized.
  91. * @return $this the relation object itself.
  92. */
  93. public function via($relationName, callable $callable = null);
  94. /**
  95. * Finds the related records for the specified primary record.
  96. * This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.
  97. * @param string $name the relation name
  98. * @param ActiveRecordInterface $model the primary model
  99. * @return mixed the related record(s)
  100. */
  101. public function findFor($name, $model);
  102. }