I have two tables in my webpage: Orders:
id int(11) NOT NULL AUTO_INCREMENT,
created datetime NOT NULL,
payed datetime DEFAULT NULL,
PRIMARY KEY (`id`)
and Order_items:
id int(11) NOT NULL AUTO_INCREMENT,
orders_id int(11) NOT NULL,
amount int(11) NOT NULL,
price float NOT NULL,
PRIMARY KEY (`id`)
One Order can have many Order_items. The example records, Orders:
id, created, payed
14, '2013-05-14 22:40:49', NULL
15, '2013-05-14 22:41:03', NULL
Order_items:
id, orders_id, amount, price
12, 14, 1, 5
13, 15, 6, 5
I need to somehow link these tables using a Model. The main thing is that the Orders result-set should contain a virtual field which would show the Order sum of money: SUM(amount*price). I'm expecting the result of the Orders table:
id, created, payed, order_sum
14, '2013-05-14 22:40:49', NULL, 5
15, '2013-05-14 22:40:49', NULL, 30
Is it possible, or it is limited by the virtual fields limits? Any help or ideas would be appreciated :)