DB relation

Hi,

I have three tables:

member


id

name

address

membership


id

code

joinDate

expDate

membershipGroup


id

memberFk

membershipFk

addedDate

Actually, I have many-to-many relationship between memebr and membership through membershipGroup. I implemented using member to membershipGroup one-to-many and membership to membershipGroup one-to-many. it works ok.

What I need is to create a relationship between member and membershipGroup so that from member I can retrieve only one row from membershipGroup with the latest addedDate without retrieving all related rows from membershipGroup.

Any one can help?

Hey Daniel,

It would be great if you will look first at the documentation provided for Relational records.

Check this links.

http://www.yiiframework.com/doc/guide/1.1/en/database.arr

http://www.yiiframework.com/forum/index.php/topic/30846-display-values-of-many-many-relationships-in-gridview/

Might be this would be helpful for you.:)

[color="#006400"]/* Moved to Yii 1.1 General Discussion */[/color]

Hi jayant,

You are right, I was thinking that I can get both HAS_MANY and HAS_ONE from member to membership. Rereading docs from the link you give, I found out that I can get it from two HAS_MANY for memberships and latestMembership relations with giving latestMembership relation a ‘limit’ = 1, of course both is sorted by ‘addedDate DESC’.

Thanks a lot for your help.

That is great ;)

Cheers !!