Producto.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * @property int|null $idSagarhpa
  14. *
  15. * @property Producto $idPadre
  16. * @property Producto[] $productos
  17. */
  18. class Producto extends ModeloBase {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName() {
  23. return 'Producto';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules() {
  29. return [
  30. [['id'], 'required'],
  31. [['creado', 'modificado', 'eliminado'], 'safe'],
  32. [['id', 'idPadre'], 'string', 'max' => 36],
  33. [['nombre'], 'string', 'max' => 100],
  34. [['idSagarhpa'], 'integer'],
  35. [['id'], 'unique'],
  36. [['idPadre'], 'exist', 'skipOnError' => true, 'targetClass' => Producto::class, 'targetAttribute' => ['idPadre' => 'id']],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels() {
  43. return [
  44. 'id' => 'ID',
  45. 'nombre' => 'Nombre',
  46. 'idPadre' => 'Id Padre',
  47. 'creado' => 'Creado',
  48. 'idSagarhpa' => 'idSagarhpa',
  49. 'modificado' => 'Modificado',
  50. 'eliminado' => 'Eliminado',
  51. ];
  52. }
  53. /**
  54. * Gets query for [[IdPadre]].
  55. *
  56. * @return \yii\db\ActiveQuery
  57. */
  58. public function getIdPadre() {
  59. return $this->hasOne(Producto::class, ['id' => 'idPadre']);
  60. }
  61. /**
  62. * Gets query for [[Productos]].
  63. *
  64. * @return \yii\db\ActiveQuery
  65. */
  66. public function getProductos() {
  67. return $this->hasMany(Producto::class, ['idPadre' => 'id']);
  68. }
  69. }