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

namespace yiiunit\data\ar\elasticsearch;
4
use yii\elasticsearch\Command;
5 6 7 8 9 10 11 12 13 14 15

/**
 * Class OrderItem
 *
 * @property integer $order_id
 * @property integer $item_id
 * @property integer $quantity
 * @property string $subtotal
 */
class OrderItem extends ActiveRecord
{
16
	public function attributes()
17
	{
18
		return ['order_id', 'item_id', 'quantity', 'subtotal'];
19 20 21 22
	}

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

	public function getItem()
	{
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
		return $this->hasOne(Item::className(), ['id' => 'item_id']);
	}

	/**
	 * 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
	}
}