Welcome Guest, Not a member yet? Register   Sign In
CI do not have model to model relationships as like Yii. Plz implement if possible.
#1

(This post was last modified: 12-14-2017, 04:49 AM by bawa_d.)

CI do not have model to model relationships as like Yii. Plz implement if possible.

example u have table_one and want to join table_two using their id

Code:
$this->db->select('columns');
$this->db->from('table_one');
$this->db->join('table_two', 'table_two.id = table_one.id');


I know with yii, you can do it this way:
Code:
$posts=Post::model()->with(
'author.profile',
'author.posts',
'categories')->findAll();


this feature should be integrated in CI4. The benefit for implementing this is user ended up with optimized query.
Reply
#2

Is it really a more optimized query? Behind the scenes, the with() command is still making joins, it's just making assumptions about what the fields on each table to join are. And, while it's true that a majority of cases will comply with that, it becomes just as verbose if you have special requirements that don't conform to the standard.

I'm not familiar enough with Yii to know, but that sounds like that call is part of an ORM system, which can make efficient queries when getting related fields, but it's not the same thing as a simple join.

CodeIgniter has always been a framework that leans more to the explicit side of code than the implicit, and this isn't expected to change much in the future.
Reply
#3

This thread may have some helpful answers: https://forum.codeigniter.com/thread-67594.html
Kristian Matthews-Kennington
Apple Certified Associate Mac Integration & Management 10.10
Reply
#4

(This post was last modified: 01-16-2018, 04:40 PM by natanfelles. Edit Reason: add example code )

If relationships are added in the Model, I believe that the configuration style of the Fuel properties are very interesting.

PHP Code:
// in a Model_Post which has many comments
protected static $_has_many = array(
 
   'comments' => array(
 
       'key_from' => 'id',
 
       'model_to' => 'Model_Comment',
 
       'key_to' => 'post_id',
 
       'cascade_save' => true,
 
       'cascade_delete' => false,
 
   )
); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB