CodeIgniter Active Record Queries W/ Sub Queries

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2012-04-03T17:15:26Z Indexed on 2012/04/03 17:28 UTC
Read the original article Hit count: 209

Filed under:
|

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:

enter image description here

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

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about activerecord