Non-Primarykey and ForeignKey Relation in Cakephp 3.x Model

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’);

   $this->belongsTo('ApplicationForms', [
        'foreignKey' => false,
        'conditions' => array(' `ApplicationForms`.`student_payment_plan_id` = 
       `StudentPaymentPlanInstallments`.`student_payment_plan_id`'),
        'dependent'  => false
    ]);

}

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.

You should use 'foreignKey' => 'student_payment_plan_id', and get rid of conditions.
If that is a unique key it should work.

If student_payment_plan_id is not unique there, than you do not have a belongsTo assocation but a belongsToMany association.

https://book.cakephp.org/3.0/en/orm/associations.html

Thanks for giving your response, i tried as you said but i got error like this
Error

Table One : StudentPaymentPlanInstallments
StudentPaymentPlanInstallments

Table Two: ApplicationForms
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.

I see.

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.