Welcome Guest, Not a member yet? Register   Sign In
new to CI, implementing relationships with the basic database library
#1

[eluser]Unknown[/eluser]
Hello all,
i'm new to CI, and wanted to know if it's possible to create one to one, one to many and many to many relationships with the basic database library.

thanks
#2

[eluser]Abdul Malik Ikhsan[/eluser]
Code:
//inner join
$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

//left join
$this->db->join('comments', 'comments.id = blogs.id', 'left');

//right join
$this->db->join('comments', 'comments.id = blogs.id', 'right');
you can see in user guide Smile
#3

[eluser]Unknown[/eluser]
Thanks for the reply.
just to be more specific.
say i have this function in my model.


function GetProjectsWebsite($options = array())
{
$this->db->order_by('project_display', 'asc');
if(isset ($options['limit']))
$this->db->limit($options['limit']);
$query = $this->db->get("projects");

return $query->result();
}

and that my projects table has a foreign key ( client_id ) to the clients table.
how would i go about adding the relationship so that the result also has the client name field from the clients table.
#4

[eluser]TaylorOtwell[/eluser]
I believe you would need an ORM for that. CodeIgniter does not have a built-in ORM. Check out Doctrine (doctrine-project.org).
#5

[eluser]WanWizard[/eluser]
Or have a look at Datamapper (see my sig), a lot lighter and faster than doctrine, and especially written for CI.




Theme © iAndrew 2016 - Forum software by © MyBB