• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI do not have model to model relationships as like Yii. Plz implement if possible.

#1
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.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

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

#4
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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