Handling many to many relationships

What is the best way to handle many to many relationships like this example:

i.e: I have 3 table:

order:

id

name

date

parameter:

id

name

value

order_parameter:

order_id

parameter_id

mystring


What’s the best way to “read” the ‘mystring’ value ? the easiest way ?

The easiest way is to use Gii to generate all your models, and then CRUD for the two models Order and Parameter.

See this post:

http://www.yiiframework.com/forum/index.php?/topic/19948-many-to-many-with-input-field/page__pid__97646#entry97646

(Do not name your tables plural - see the guide for suggested naming conventions)

OrderParameter::model()->find(array(‘condition’ => “order_id = $order_id and parameter_id = $parameter_id”))->mystring;

Did you just ask a trick question?


 $orders = Order::model()->findAll();

foreach($orders as $order) {

  foreach($order->order_parameters as $order_parameter) {

	echo $order_parameter->name;

  }

}

The easiest way of getting the ‘mystring’ value is to set up the relations between the models properly.

Nice answer, after 10 hours of coding, my brain is sizzling now! sorry for this question !

No problems! I know exactly how it feels. :lol: