K
K
Kirill Gorlov2015-06-23 12:26:07
ORM
Kirill Gorlov, 2015-06-23 12:26:07

How to change the link key in Kohana 3 ORM?

There are two tables: Orders (id/number/summ/datetime) and Dishes (id/order_number/name/cost)
And there is a link in the order model for selecting dishes

protected $_has_many = array(
    'dishes' => array(
      'model' => 'dishes',
      'foreign_key' => 'order',
    ),
  );

The essence of the question, how to specify for the connection to which parameter to bind (instead of ID to the order number)?
protected $_has_many = array(
    'dishes' => array(
      'model' => 'dishes',
      'foreign_key' => 'order',
      'table_id' => 'number' // Этого нет конечно, но чтонибудь типо такого было бы неплохо.
    ),
  );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2015-06-23
@Chetson

You somehow design the database incorrectly, describe what exactly you want to get as a result . You
can order 1 dish several times, the same thing in 1 order there can be several dishes, i. You need to use the belongs to relationship (many to many)
PS Model names in Kohana are usually referred to in the singular (except for exceptions)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question