Welcome Guest, Not a member yet? Register   Sign In
[solved] Can DB Models represent relationships in CI?
#1

[eluser]nottRobin[/eluser]
I just installed CodeIgniter, and read through everything under "General Topics" and then relevant 'Class Reference' sections in the documentation.

I like CodeIgniter it's simple and fast and can do most things I want.

The only thing I can think of that it's missing is the ability to represent relationships in its Models - but unfortunately I think this is quite a big drawback.

Say I have the following many-to-many relationship: A 'user' table and a 'group' table. Each 'user' can be a member of multiple groups, and each 'group' can have multiple users. Therefore I have a joining table called 'user_group' linking 'user_id' to 'group_id'.

In an Object Relational Mapper like Doctrine you can configure the models to understand this relationship, and then do something like this:

Code:
$user->groups; // An array of all groups that the user belongs to
$group->users; // An array of all users in the group

Is there any way to do this in CodeIgniter? Or is there a plugin I can use to add this functionality?

Cheers,
Robin.
#2

[eluser]nottRobin[/eluser]
I just found DataMapper OverZealous Edition which covers everything I need.

Does anyone know how DMZ compares to Doctrine? And also - is there a standard page which lists CI plugins like this?

Cheers,
Robin.
#3

[eluser]jedd[/eluser]
Hi Robin,

An alternative is to have a model that looks after users and groups (consequently it would own all three tables in your example).

DMZ seems to be more popular around these parts - and I gather (though have never had the interest or experience) that Doctrine can be slightly challenging to wedge into CI.

There's a few forum threads, and I think a wiki article or two, on the subject however. I'd suggest you have a play with both though, just to be sure. Certainly Phil seems to be very active in supporting and developing the DMZ library - so I'd think you're on a pretty safe bet with it.
#4

[eluser]nottRobin[/eluser]
Thanks jedd that's helpful.

I haven't been able to find much on integrating Doctrine with CI so I don't think I'll bother with Doctrine (even though I'm more familiar with it). From what I can tell DMZ covers everything I need, and it's wonderfully well documented and of course well integrated into CI.

Thanks again.
#5

[eluser]nottRobin[/eluser]
Oh and to answer my other question about whether there's a list of contributed libraries and plugins etc. I found out that there is here:

http://codeigniter.com/wiki/
http://codeigniter.com/wiki/Libraries
http://codeigniter.com/wiki/Plugins

I think I'm going to see if I can mark this thread as 'solved' now.
#6

[eluser]Watermark Studios[/eluser]
Be sure to check out CodeIgniter and Doctrine from Scratch

That is a killer tutorial on setting up a CI app using Doctrine. I have used DataMapper and DMZ and I find that Doctrine is more robust. On the other hand, robust <> better. I like them all, but I currently use Doctrine when I can. I am having an issue with the many-to-many relationship table constraints. I have followed Doctrine's documentation exactly and still can't get them to work properly. I may have to revert to DMZ until I can figure out what is wrong.

Hope this helps,

Ken




Theme © iAndrew 2016 - Forum software by © MyBB