OrderItem.php 1.2 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 19 20
    public function attributes()
    {
        return ['order_id', 'item_id', 'quantity', 'subtotal'];
    }
21

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

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

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    /**
     * 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"],
                ]
            ]
        ]);
49

50
    }
51
}