Questions about HAS_MANY relation in AR

[size=“4”]For example I’ve 4 tables:[/size]





[size=“4”]in user_review_image table there’s user_is, image_id and review_id.[/size]

[size=“4”]1. Should I use Has_Many or Many_Many? because I’ve problem understanding the difference between them.[/size]

[size=“4”]2. Do I’ve to define a Model (using Gii) for user_review_image table? or just using ‘through’=>‘user_review_image’ in relations() will be enough?[/size]

[size=“4”]before you ask, I already checked “[/size][size=2]Relational Active Record” in Yii’s definitive guide but I still don’t get it.[/size]

[size=2]please help me if you can.[/size]

Hi TripleM, I never want to pass any judgements on what people do or do not know…but the question you are asking is more database specific. Yii relations just use what you have defined in your db.

If the db relation is HAS_MANY then so your Yii relation and same with MANY_MANY. Two HAS_MANY relations (between 3 tables) is the same as MANY_MANY.

Yii relations add the flexibility to use whatever relation you need to when getting the job done. i.e. I have many tables relations defined in Yii that have a mixture of BELONGS_TO, HAS_ONE, HAS_MANY or MANY_MANY depending on the info I am pulling/using in that part of my code.