CodeIgniter Active Record Queries W/ Sub Queries
- by Mike
Question:
I really am trying to stick to using ActiveRecord and not using straight SQL.. can someone help me convert this to activerecord?
Trying to get the email address and contact name from another table. map_userfields table is a one to many, multiple rows per p.id. one row per p.id per uf.fieldid.
see this screenshot for a reference to the map_userfields table:
Current Non active record query
SELECT
p.id,
(SELECT uf.fieldvalue FROM map_userfields uf WHERE uf.pointid = p.id AND uf.fieldid = 20) As ContactName,
(SELECT uf.fieldvalue FROM map_userfields uf WHERE uf.pointid = p.id AND uf.fieldid = 31) As ContactEmail
FROM
map_points p
WHERE
/** $pointCategory is an array of categories to look for **/
p.type IN($pointCategory)
Note: I am using CodeIgniter 2.1.x, MySQL 5.x, php 5.3