Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



18.5k
Accepted
answer

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

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