php - Many to Many Relationships -


i'm seeing sorts of different ways handle many many relationships in yii. however, examples i'm seeing aren't fleshed out , feel i'm missing something.

for instance, larry ullman's tutorial doesn't use self::many_many relation - http://www.larryullman.com/2010/08/10/handling-related-models-in-yii-forms/

so far adding , retrieving records, whats standard way handling many many in model, controller , view?

clarification: suppose im looking example involving 2 tables, related many-to-many, can see not both models, controllers , views can understand whats going on.

you need 3 tables (so model pivot table), once have can use regular yii relation functionality.

for example project of mine has many-to-many relation between purchase , transaction (please don't ask why :) ). there purchase model, transaction model , purchasetotransaction model establishes links between them. can $opurchase->transactions , yii handle many-to-many part using relation, defined follows:

'transactions' => array(self::many_many, 'transaction', 'purchasetotransaction(purchaseid, transactionid)') 

note transactions, same applies other way around:

'purchases'   => array(self::many_many, 'purchase', 'purchasetotransaction(transactionid, purchaseid)'), 

so both $opurchase->transactions , $otransaction->purchases automatically handled yii.

in conclusion can indeed handle many-to-many using relations (at least reading part, writing still need arbitrary solutions).


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -