ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Need help with Active Record

November 29, 2010 3:12pm

Subscribe [1]
  • #1 / Nov 29, 2010 3:12pm

    Joseph Wensley

    38 posts

    I’m trying to do an SQL query with ActiveRecord but it keeps causing a fatal error because it is using too much memory.

    In plain old SQL this works.

    $query = $EE->db->query("SELECT c.cat_name, c.cat_url_title FROM exp_channel_titles AS t 
        INNER JOIN exp_category_posts AS cp ON cp.entry_id = t.entry_id 
        INNER JOIN exp_categories AS c ON cp.cat_id = c.cat_id
        WHERE t.url_title = {$segment_3} AND t.channel_id=7 AND c.group_id=1"
    );

    But when I converted it to active record it broke

    $EE->db->select('c.cat_name, c.cat_url_title');
    $EE->db->join('exp_category_posts AS cp', 'cp.entry_id = t.entry_id');
    $EE->db->join('exp_categories AS c', 'cp.cat_id = c.cat_id');
    $EE->db->where('c.group_id', 1);
    $EE->db->where('t.channel_id', 7);
    $EE->db->where('t.url_title', '{segment_3}');
    $query = $EE->db->get('exp_channel_titles AS t');

    Is there something I’m doing wrong in the active record version?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases