We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

relationship using multiple column

Hey community!

i have an annual report table & subtables. i want to create relationship of those tables using 2 column. on sql would be like this:

FROM
    report
JOIN
    report_subjects
ON
    report.item_id = report_subjects.item_id
AND
    report.year_id = report_subjects.year_id

how to make it in phalcon?

thanx in advance

thx RompePC for replying.

i've read that docs, but hasMany() method only mentioning 1 column to create relationship between models. i want to use 2 column.

there are situations that I want to achieve by using multiple column in relationship:

  1. simplify SQL insertion statement
  2. simplify sql transaction flow when operating with those table
  3. avoid complexity when i have to do manual insertion in phpmyadmin

is there any suggestion?



33.8k
Accepted
answer

Try this (but I don't think it will work):

$this->hasMany(
    array('id', 'year'),
    'ReportSubjects',
    array('item_id', 'year_id')
);