У меня есть CountryTable, где я могу найти, среди прочего, поля «имя» и «валюта».
В настоящее время у меня есть следующие определения таблиц:
class ProducsTable extends Table {
public function initialize(array $config) {
$this->table('products');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->hasMany('Productprices', [
'foreignKey' => 'product_id',
]);
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
]);
}
}
class ProductpricesTable extends Table {
public function initialize(array $config) {
$this->table('productprices');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
]);
}
}
class CountryTable расширяет таблицу {
public function initialize(array $config) {
$this->table('countries');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->hasMany('Products', [
'foreignKey' => 'product_id',
]);
$this->hasMany('Productprices', [
'foreignKey' => 'product_id',
]);
}
}
Итак, у меня есть продукт, в котором указана страна происхождения и список цен, связанных с валютой.
Когда я создаю продукт, у меня есть следующая форма:
<?= $this->Form->input('name', ['label' => __("Name :")]); ?>
<?= $this->Form->input('country_id', ['label' => __("Origin :")]); ?>
<?= $this->Form->input('pricelist.0.value', ['label' => __("Price :")]); ?>
<?= $this->Form->input('pricelist.0.country_id', ['label' => __("Currency :")]); ?>
Конечно, оба input('country_id')
отображают список имен, тогда как я бы хотел, чтобы второй отображал список валют.
Как сделать?
В основном я хотел создать копию CountryTable с именем CurrenciesTable, указывающую на ту же таблицу «страны», и связать Productprices с CurrenciesTable... но звучит странно... нет?