We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Table alias in join

Development and Programming

Joseph Wensley's avatar
Joseph Wensley
38 posts
15 years ago
Joseph Wensley's avatar Joseph Wensley

Does anyone know if you can use table aliases in ActiveRecord joins?

Doing the below query just gives me a fatal error saying I’ve run out of memory (with the memory limit set to 250M), but if I remove the table aliases it works.

<?php

$cats = array(1,28);

$this->EE->db->select('*');
$this->EE->db->join('exp_category_posts as cp', 'cp.entry_id = t.entry_id');
$this->EE->db->join('exp_channel_data as d', 'd.entry_id = t.entry_id');
$this->EE->db->join('exp_categories as c', 'c.cat_id = cp.cat_id');
$this->EE->db->where('t.channel_id', 3);
$this->EE->db->where_in('cp.cat_id', $cats);
$query = $this->EE->db->get('exp_channel_titles as t');

var_dump($query);

?>

Is there something special I have to do to get an alias to work or will they just not work in this situation?

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

Odd, we use them all over the place in the EE Core code. If you EXPLAIN the raw query, what do you get?

-greg

       
Joseph Wensley's avatar
Joseph Wensley
38 posts
15 years ago
Joseph Wensley's avatar Joseph Wensley

You mean like?

EXPLAIN SELECT * FROM exp_channel_titles as t 
JOIN exp_category_posts as cp ON cp.entry_id = t.entry_id 
JOIN exp_channel_data as d ON d.entry_id = t.entry_id 
JOIN exp_categories as c ON c.cat_id = cp.cat_id 
WHERE t.channel_id = 3 AND cp.cat_id IN (1,28)

I get this

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

double odd.

What’s the exact error? How many queries are on the pages? Front end or back end?

       
Joseph Wensley's avatar
Joseph Wensley
38 posts
15 years ago
Joseph Wensley's avatar Joseph Wensley

The error is

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes) in web/content/system/codeigniter/system/database/DB_driver.php on line 1176

It’s running in a template and the only code in it is what I posted above.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.