# How to associate one table non Primary key to others tables non foreign key in CakePHP2?

**URL:** <https://discourse.cakephp.org/t/how-to-associate-one-table-non-primary-key-to-others-tables-non-foreign-key-in-cakephp2/9630>\
**Category:** Need Help\
**Created:** [August 13, 2021, 6:24pm UTC](https://discourse.cakephp.org/t/how-to-associate-one-table-non-primary-key-to-others-tables-non-foreign-key-in-cakephp2/9630 "2021-08-13T18:24:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhumi](https://avatars.discourse-cdn.com/v4/letter/b/edb3f5/32.png) [@bhumi](https://discourse.cakephp.org/u/bhumi)\
**Post date:** [August 13, 2021, 6:24pm UTC](https://discourse.cakephp.org/t/how-to-associate-one-table-non-primary-key-to-others-tables-non-foreign-key-in-cakephp2/9630/1 "2021-08-13T18:24:52Z")

</div>

Example:

1. Staff(relation\_id(non primary key))
2. Teacher(teacher\_id(non primary key))
3. Vendors(vendor\_id(non primary key))

Now, teacher\_id = relation\_id for the relationship with the Teacher to Staff  
vendor\_id = relation\_id for the relationship with the Vendors to Staff

In, Staff table I’m associating in Staff.php like below:

```auto
public $belongsTo = array(
        'Teacher' => array(
            'className' => 'Teacher',
            'foreignKey' => false,
            'conditions' => array('Teacher.is_deleted' => 0, '`Staff`.`relation_id` = `Teacher`.`teacher_id`'),
            'fields' => '',
            'order' => '',
            'dependent' => false
        ),
        'Vendor' => array(
            'className' => 'Vendor',
            'foreignKey' => false,
            'conditions' => array('Vendor.is_deleted' => 0, '`Staff`.`relation_id` = `Vendor`.`vendor_id`'),
            'fields' => '',
            'order' => '',
            'dependent' => false
        ),
    );

```

But its not working, can anyone have idea in cakephp2?
