I want to combine tables with multiple foreign keys with the association function of cakephp.

Asked 1 years ago, Updated 1 years ago, 76 views

[Environment]
  PHP 5.3.19
  Cakephp 2.6.1

Is it possible to associate if there are multiple foreign keys as shown below?

 [hoge_one table]
id,
foreign_code_1,
foreign_code_2,
date,


[hoge_many table]
id,
foreign_code_1,
foreign_code_2,
hoge,
data,
etc

   h The merge key that connects the hoge_many table to hoge_one is:
      Only foreign_code_1, foreign_code_2.(no foreign key added)
   h I would like to associate from hoge_one to hoge_many by hasmany.

Thank you for your cooperation.

php cakephp

2022-09-30 21:12

1 Answers

public$hasMany=array(
    'HogeMany' = > array(
        'foreignKey' = > 'foreign_code_1',
        'conditions' = > array('HogeMany.foreign_code_2' = > 'HogeOne'.foreign_code_2),
    )
);


2022-09-30 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.