Sophisticated model, question

#1
[eluser]evgeny_likov[/eluser]
Hi lads.

How to make model with three JOINs? I have few tables: 'topics', 'messages', 'users', 'profiles', and tables linked one another with _id fields:

topics: id, user_id
messages: id, topic_id
users: id, profile_id
profiles: id, first_name, last_name

I need to get from my model topic with all belonged messages and first+last names from profiles. Is it possible?

#2
[eluser]fdog[/eluser]
I think it's possible. Try this:
Code:
$this->db->select('first_name, last_name');
$this->db->from('profiles');
$this->db->join('messages', 'messages._id = profiles._id');

$query = $this->db->get();

#3
[eluser]Chris Newton[/eluser]
You can do simple joins with Active Record, but you can't currently use Active Record for Many-To-Many relationships.

If you're trying to pull data with a many-to-many relationship, you will find that it CAN'T be done with Active Record. It can be done with CI database methods, but not with Active Record. You'll need to build some of your own MySQL queries if you plan to use anything beyond a one-to-one relationship with your datbase calls.

#4
[eluser]evgeny_likov[/eluser]
Thank you, fdog, but it is not quite what i need. I need two or three joins at same time.

#5
[eluser]evgeny_likov[/eluser]
mahuti, thank you for answer. It's just i need.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.