Producto.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "Producto".
  6. *
  7. * @property string $id
  8. * @property string|null $nombre
  9. * @property string|null $idPadre
  10. * @property string|null $creado
  11. * @property string|null $modificado
  12. * @property string|null $eliminado
  13. *
  14. * @property Producto $idPadre
  15. * @property Producto[] $productos
  16. */
  17. class Producto extends ModeloBase {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName() {
  22. return 'Producto';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules() {
  28. return [
  29. [['id'], 'required'],
  30. [['creado', 'modificado', 'eliminado'], 'safe'],
  31. [['id', 'idPadre'], 'string', 'max' => 36],
  32. [['nombre'], 'string', 'max' => 100],
  33. [['id'], 'unique'],
  34. [['idPadre'], 'exist', 'skipOnError' => true, 'targetClass' => Producto::class, 'targetAttribute' => ['idPadre' => 'id']],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels() {
  41. return [
  42. 'id' => 'ID',
  43. 'nombre' => 'Nombre',
  44. 'idPadre' => 'Id Padre',
  45. 'creado' => 'Creado',
  46. 'modificado' => 'Modificado',
  47. 'eliminado' => 'Eliminado',
  48. ];
  49. }
  50. /**
  51. * Gets query for [[IdPadre]].
  52. *
  53. * @return \yii\db\ActiveQuery
  54. */
  55. public function getIdPadre() {
  56. return $this->hasOne(Producto::class, ['id' => 'idPadre']);
  57. }
  58. /**
  59. * Gets query for [[Productos]].
  60. *
  61. * @return \yii\db\ActiveQuery
  62. */
  63. public function getProductos() {
  64. return $this->hasMany(Producto::class, ['idPadre' => 'id']);
  65. }
  66. }