You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ActiveQueryInterface.php 3.9KB

преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * Sets the [[indexBy]] property.
  31. * @param string|callable $column the name of the column by which the query results should be indexed by.
  32. * This can also be a callable (e.g. anonymous function) that returns the index value based on the given
  33. * row or model data. The signature of the callable should be:
  34. *
  35. * ```php
  36. * // $model is an AR instance when `asArray` is false,
  37. * // or an array of column values when `asArray` is true.
  38. * function ($model)
  39. * {
  40. * // return the index value corresponding to $model
  41. * }
  42. * ```
  43. *
  44. * @return $this the query object itself
  45. */
  46. public function indexBy($column);
  47. /**
  48. * Specifies the relations with which this query should be performed.
  49. *
  50. * The parameters to this method can be either one or multiple strings, or a single array
  51. * of relation names and the optional callbacks to customize the relations.
  52. *
  53. * A relation name can refer to a relation defined in [[ActiveQueryTrait::modelClass|modelClass]]
  54. * or a sub-relation that stands for a relation of a related record.
  55. * For example, `orders.address` means the `address` relation defined
  56. * in the model class corresponding to the `orders` relation.
  57. *
  58. * The following are some usage examples:
  59. *
  60. * ```php
  61. * // find customers together with their orders and country
  62. * Customer::find()->with('orders', 'country')->all();
  63. * // find customers together with their orders and the orders' shipping address
  64. * Customer::find()->with('orders.address')->all();
  65. * // find customers together with their country and orders of status 1
  66. * Customer::find()->with([
  67. * 'orders' => function (\yii\db\ActiveQuery $query) {
  68. * $query->andWhere('status = 1');
  69. * },
  70. * 'country',
  71. * ])->all();
  72. * ```
  73. *
  74. * @return $this the query object itself
  75. */
  76. public function with();
  77. /**
  78. * Specifies the relation associated with the junction table for use in relational query.
  79. * @param string $relationName the relation name. This refers to a relation declared in the [[ActiveRelationTrait::primaryModel|primaryModel]] of the relation.
  80. * @param callable $callable a PHP callback for customizing the relation associated with the junction table.
  81. * Its signature should be `function($query)`, where `$query` is the query to be customized.
  82. * @return $this the relation object itself.
  83. */
  84. public function via($relationName, callable $callable = null);
  85. /**
  86. * Finds the related records for the specified primary record.
  87. * This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.
  88. * @param string $name the relation name
  89. * @param ActiveRecordInterface $model the primary model
  90. * @return mixed the related record(s)
  91. */
  92. public function findFor($name, $model);
  93. }