Lets call your table that you need to create conversions, with a
Conversion model

To relate the a model to the same model twice use the following(for
your Conversion model)
$belongsTo = array(
'Unit1' => array("className" => "Unit", "foreignKey" => "unit1_id"),
'Unit2' => array("className" => "Unit", "foreignKey" => "unit2_id"),
)

and in your Unit model
$hasMany = array(
'Conversion'
)

And the conditions to find the right conversion row could look like
this(assuming $unit1 and $unit2 holds the ids of the units to convert
to/from)

'conditions' => array('OR' => array(
                                    'AND' =>
array('Conversion.unit1_id' => $unit1, 'Conversion.unit2_id' =>
$unit2),
                                    'AND' =>
array('Conversion.unit1_id' => $unit2, 'Conversion.unit2_id' =>
$unit1)
                                   ))


On Jul 12, 10:36 am, Tomek Mazur <tmazu...@gmail.com> wrote:
> Hi guys,
>
> I could use some help with the complicated relation I am trying to
> create. I have 2 tables: ingredients and units. One ingredient can
> have many units(HABTM relation). This creates a `ingredients_units`
> table with the fields:
>
> -ingredient_id
> -unit_id
> -ammount
>
> But the problem is, that if an ingredient has many units I have to
> somehow be able to convert between each unit. The complication is that
> the calculations from one unit to another depend on the ingredient. So
> the table I am wanting to create has to have the following fields:
>
> -ingredient_id
> -unit1_id
> -unit2_id
> -conversion_number
>
> Is there a way I can create such a relation with Cake? Or do I have to
> stick to my own SQL? I'll be thankful for any response. ;)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to