E
E
entermix2015-08-13 17:45:37
Kohana
entermix, 2015-08-13 17:45:37

How to execute a subquery in ORM?

There are tables:
orders:
id, author_id, consumer_id, supplier_id, manager_id, status_id, created
orders_archive
id, order_id, user_id
,
created which were created by the current user, and which were added / not added to the archive (by the same user)

$orders = ORM::factory('Order')
->where('author_id', '=', $this->user->id)
->and_where(?)

How to insert such a subquery? Do I understand correctly that DB::expr() should be used? How?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bkosun, 2015-08-14
@entermix

->where(null, 'EXISTS', DB::expr('(SELECT * FROM `order_archive` AS `oa` WHERE `oa`.`order_id` = `order`.`id` AND ...)'))

C
ChernovGV, 2015-08-14
@ChernovGV

$orders = ORM::factory('Order')
->join('orders_archive', 'LEFT')->on('orders.id', '=', 'orders_archive.order_id')
->where('author_id', '=', $this->user->id)
->and_where(?)

Well, you need to specify what kind of ORM we are talking about!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question