-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get data from 2 tables joint in abother table #219
Comments
I ended up writing my own custom models and extending the CI_Model :
It works but its not using the efficient MY_MODEL, how do I integrate this with MY_MODEL ? So that I end up not writing too much code like above ? |
@absmugz you can write method Class My_mega_model extends MY_Model {
//Add line below, if you always need join`s
protected $before_get = array('with_my_stuff');
public function with_my_stuff()
{
//here you join tables code goes here
return $this;
}
} |
Thanks Michail1982,
|
check docs. before_get must accept and return $row my example explaining idea ;) |
If you're that familiar in creating queries, you can just create a view on your database. Then just create an instance of that view with your models and treat is a normal table. This is what works for me and what I am used to. Of course you still need to create separate model for each tables that you used on your view for the management of those table. And also, take note, you don't update and/or write on your view directly, you need to update and/or write on the table(s) that you joined together, the view will then be automatically updated because it is just pulling the records/data from your source tables. |
@michail1982 your example is returning $this, not $row... |
@paulcanning i know)) . my example can be used in case $this->my_mega->model->with_my_stuff()->get();/// or any other AR method when with_my_stuff in before_get array method must receive and return some varible |
Hi,
I have a simple database which uses joins as follows :
Table 1 contains portfolio items:
Portfolio_items
portfolio_id
name
description
Table 2 contains portfolio categories:
Categories
categories_id
name
Table 3 contains the portfolio categories join ids:
Portfolio_categories
portfolio_id
categories_id
So what I would like to do is get all 1 record from Portfolio_items and all the categories that 1 portfolio item is in.
Basically please point me in the right direction of how to get data from Portfolio_items with multiple and Categories where the joines are in id's in Portfolio_categories using MY_Model.
Do I have to write custom functions like :
class A_model extends MY_Model
{
public function Example()
{
Custom ActiveRecord query goes here
}
}
Can you please give me a rough example using the table structure above ? Thank you
The text was updated successfully, but these errors were encountered: