CodeIgniter Forums
combining multiple activerecord queries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: combining multiple activerecord queries (/thread-26725.html)



combining multiple activerecord queries - El Forum - 01-21-2010

[eluser]walrusk[/eluser]
Hey there

I'm pretty new to activerecord and mysql, but I'm picking it up quick so bear with me!

My question is whether or not it is possible to combine the following two queries into one:

Code:
$this->db->where('id',$this->uri->segment(3));
$data['folder'] = $this->db->get('folders');
            
$this->db->where('folder_id',$this->uri->segment(3));
$data['files'] = $this->db->get('files');

Basically I'm displaying a page of files contained in one folder. I also need the single row from the folder table so that I can display the folder title and other info.

I've looked into joins a bit, and I think I understand them somewhat, but I'm not sure if I can use them in a situation like this - can I? If not: is there another way to achieve this?

Any help is much appreciated! Thanks to all you Igniters of Code!


combining multiple activerecord queries - El Forum - 01-21-2010

[eluser]danmontgomery[/eluser]
Code:
$this->db->select("folders.some_field, files.some_other_field")->join("files", "files.folder_id = folders.id")->where("folders.id", $folder_id)->get("folders");



combining multiple activerecord queries - El Forum - 01-23-2010

[eluser]walrusk[/eluser]
I tried that - but I can't seem to figure out how to get "folders.some_field" out of the resulting object. Is it definitely being included?