OrderItem.php 1.22 KB
Newer Older
1 2 3
<?php

namespace yiiunit\data\ar\elasticsearch;
AlexGx committed
4

5
use yii\elasticsearch\Command;
6 7 8 9 10 11 12 13 14 15 16

/**
 * Class OrderItem
 *
 * @property integer $order_id
 * @property integer $item_id
 * @property integer $quantity
 * @property string $subtotal
 */
class OrderItem extends ActiveRecord
{
17 18
    public $total;

19 20 21 22
    public function attributes()
    {
        return ['order_id', 'item_id', 'quantity', 'subtotal'];
    }
23

24 25 26 27
    public function getOrder()
    {
        return $this->hasOne(Order::className(), ['id' => 'order_id']);
    }
28

29 30 31 32
    public function getItem()
    {
        return $this->hasOne(Item::className(), ['id' => 'item_id']);
    }
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    /**
     * sets up the index for this record
     * @param Command $command
     */
    public static function setUpMapping($command)
    {
        $command->deleteMapping(static::index(), static::type());
        $command->setMapping(static::index(), static::type(), [
            static::type() => [
                "properties" => [
                    "order_id" => ["type" => "integer"],
                    "item_id"  => ["type" => "integer"],
                    "quantity" => ["type" => "integer"],
                    "subtotal" => ["type" => "integer"],
                ]
            ]
        ]);
51

52
    }
53
}