How to solve the Non Primary Key with Foreign Key relation in cakephp 3.x Model using belongsTo ?
I tried like this…
public function initialize(array $config){
parent::initialize($config);
$this->setTable(‘StudentPaymentPlanInstallments’);
$this->setDisplayField(‘id’);
$this->setPrimaryKey(‘id’);
Note: In above condition StudentPaymentPlanInstallments.student_payment_plan_id is not a primary key, so any one help me for this issue in cakephp 3.x version.
Thanks for giving your response, i tried as you said but i got error like this
Table One : StudentPaymentPlanInstallments
Table Two: ApplicationForms
Note: I want relationship between StudentPaymentPlanInstallments(Table One) to ApplicationForms(Table Two) based on student_payment_plan_id in cakephp Model 3.x version.
These two models are NOT associated to each other, that is why you run into problems.
Based on the names I think in your database there is a tabke named StudentPaymantPlan where the id is primary key. Both of your tables are associated with this table.
Please read the linked chapter from the cookbook to get a clearer picture what you are working with.
An other suggestion: import your data structure to MySQL Workbench and you will visually see the associations (if you have foreign key constrains). It will help you.