php - Model store with different column than primaryKey -
i have laravel/octobercms model interface exchangemodel.
it's 1 sided relationship exchangemodel. stores in customer database table via exchangemodel.id. i'd store exchangemodel.currencyiso, 3 letter country code.
what need setup in relation laravel store via other field try define via otherkey or key instead of primarykey(id)?
<?php namespace phuntime\client\models; use model; /** * customer model */ class customer extends model { /** * @var string database table used model. */ public $table = 'customer'; public $primarykey = 'customernumber'; /** * @var array relations */ public $belongsto = ['currency' => ['phuntime\exchangerate\models\exchangemodel', 'key' => 'currencyiso',// eur,usd,yen 'otherkey' => 'currencyiso' ]]; }
clarification of structure:
- customer - id - name - currency(varchar(3)) <-- relation - exchangemodel - id - currencyiso
currently exchangemodel.id gets stored in customer.currency
i want exchangemodel.currencyiso stored in customer.currency customer.currency varchar field suitable accept it.
currently if specify type:relation
in fields.yaml stores exchangemodel.id
no matter specify how should store it. use of otherkey, foreignkey, key, nothing helps changing octobers mind.
currently i'm using type: dropdown
populate via getcurrencyoptions()
in feeling less ideal situation.
Comments
Post a Comment