Order.php 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace yiiunit\twig\data;
  3. use yii\db\ActiveRecord;
  4. use yii\db\Connection;
  5. /**
  6. * Class Order
  7. *
  8. * @property integer $id
  9. * @property integer $customer_id
  10. * @property integer $created_at
  11. * @property string $total
  12. */
  13. class Order extends ActiveRecord
  14. {
  15. public static $db;
  16. public static function getDb()
  17. {
  18. if (static::$db === null) {
  19. static::$db = new Connection(['dsn' => 'sqlite::memory:']);
  20. }
  21. return static::$db;
  22. }
  23. public static function setUp()
  24. {
  25. static::getDb()->createCommand(<<<SQL
  26. CREATE TABLE "order" (
  27. id INTEGER NOT NULL,
  28. customer_id INTEGER NOT NULL,
  29. created_at INTEGER NOT NULL,
  30. total decimal(10,0) NOT NULL,
  31. PRIMARY KEY (id)
  32. );
  33. SQL
  34. )->execute();
  35. }
  36. public static function tableName()
  37. {
  38. return 'order';
  39. }
  40. public function getCustomer()
  41. {
  42. return $this->hasOne(Order::class, ['id' => 'customer_id']);
  43. }
  44. }