Welcome Guest, Not a member yet? Register   Sign In
combining multiple activerecord queries
#1

[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!
#2

[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");
#3

[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?




Theme © iAndrew 2016 - Forum software by © MyBB