ActiveQueryInterface.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * A class implementing this interface should also use [[ActiveQueryTrait]].
  12. *
  13. * @author Qiang Xue <[email protected]>
  14. * @author Carsten Brandt <[email protected]>
  15. * @since 2.0
  16. */
  17. interface ActiveQueryInterface extends QueryInterface
  18. {
  19. /**
  20. * Sets the [[asArray]] property.
  21. * @param boolean $value whether to return the query results in terms of arrays instead of Active Records.
  22. * @return static the query object itself
  23. */
  24. public function asArray($value = true);
  25. /**
  26. * Sets the [[indexBy]] property.
  27. * @param string|callable $column the name of the column by which the query results should be indexed by.
  28. * This can also be a callable (e.g. anonymous function) that returns the index value based on the given
  29. * row or model data. The signature of the callable should be:
  30. *
  31. * ~~~
  32. * // $model is an AR instance when `asArray` is false,
  33. * // or an array of column values when `asArray` is true.
  34. * function ($model)
  35. * {
  36. * // return the index value corresponding to $model
  37. * }
  38. * ~~~
  39. *
  40. * @return static the query object itself
  41. */
  42. public function indexBy($column);
  43. /**
  44. * Specifies the relations with which this query should be performed.
  45. *
  46. * The parameters to this method can be either one or multiple strings, or a single array
  47. * of relation names and the optional callbacks to customize the relations.
  48. *
  49. * A relation name can refer to a relation defined in [[modelClass]]
  50. * or a sub-relation that stands for a relation of a related record.
  51. * For example, `orders.address` means the `address` relation defined
  52. * in the model class corresponding to the `orders` relation.
  53. *
  54. * The followings are some usage examples:
  55. *
  56. * ~~~
  57. * // find customers together with their orders and country
  58. * Customer::find()->with('orders', 'country')->all();
  59. * // find customers together with their orders and the orders' shipping address
  60. * Customer::find()->with('orders.address')->all();
  61. * // find customers together with their country and orders of status 1
  62. * Customer::find()->with([
  63. * 'orders' => function($query) {
  64. * $query->andWhere('status = 1');
  65. * },
  66. * 'country',
  67. * ])->all();
  68. * ~~~
  69. *
  70. * @return static the query object itself
  71. */
  72. public function with();
  73. }