Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

86 lines
1.9KB

  1. <?php
  2. namespace domain\Product\ProductAccessory;
  3. use common\components\ActiveRecordCommon;
  4. use domain\Product\Accessory\Accessory;
  5. use domain\Product\Product\Product;
  6. use yii\db\ActiveQuery;
  7. class ProductAccessory extends ActiveRecordCommon
  8. {
  9. public static function tableName()
  10. {
  11. return 'product_accessory';
  12. }
  13. public function rules()
  14. {
  15. return [
  16. [['id_product', 'id_accessory', 'quantity'], 'required'],
  17. [['id_product', 'id_accessory', 'quantity'], 'integer'],
  18. ];
  19. }
  20. public function attributeLabels()
  21. {
  22. return [
  23. 'id' => 'ID',
  24. 'id_product' => 'Produit',
  25. 'id_accessory' => 'Accessoire',
  26. 'quantity' => 'Quantité',
  27. ];
  28. }
  29. /* Getters / Setters */
  30. public function getId(): ?int
  31. {
  32. return $this->id;
  33. }
  34. public function getProduct(): Product
  35. {
  36. return $this->productRelation;
  37. }
  38. public function setProduct(Product $product): self
  39. {
  40. $this->populateFieldObject('id_product', 'productRelation', $product);
  41. return $this;
  42. }
  43. public function getAccessory(): Accessory
  44. {
  45. return $this->accessoryRelation;
  46. }
  47. public function setAccessory(Accessory $accessory): self
  48. {
  49. $this->populateFieldObject('id_accessory', 'accessoryRelation', $accessory);
  50. return $this;
  51. }
  52. public function getQuantity(): ?int
  53. {
  54. return $this->quantity;
  55. }
  56. public function setQuantity(?int $quantity): self
  57. {
  58. $this->quantity = $quantity;
  59. return $this;
  60. }
  61. /* Relations */
  62. public function getProductRelation(): ActiveQuery
  63. {
  64. return $this->hasOne(Product::class, ['id' => 'id_product']);
  65. }
  66. public function getAccessoryRelation(): ActiveQuery
  67. {
  68. return $this->hasOne(Accessory::class, ['id' => 'id_accessory']);
  69. }
  70. }