Reputation: 245
I'm using CakePHP v3
I have a table that looks like this:
Document:
id | section | paragraph
-------------------------
1 2 4
Text:
id | section | paragraph | theText
---------------------------------------
12 2 4 Blah blah
So in SQL I could do something like this;
SELECT * FROM document
INNER JOIN text
ON document.section=text.section
AND document.paragraph=text.paragraph
How can I do something like this in CakePHP using the ORM? The Primary key in both tables is set up to be the id column.
I've looked into foreignKey
and binidingKey
in Cake's docs, but I can't see how to use multiple columns in those.
http://book.cakephp.org/3.0/en/orm/associations.html.
FWIW, here is a sample of code that shows how I want to access them.
$cond = [
'contain' => ['text']
];
$docs = $this->Documents->find('all',$cond);
Upvotes: 1
Views: 1458
Reputation: 9614
Yes, it is possible. Just use arrays to express the columns that should be matched:
$this->belongsTo('Things', [
'bindingKey' => ['key1', 'ke2'],
'foreignKey' => ['fk1', 'fk2']
]);
That will match key1 = fk1
and key2 = fk2
Upvotes: 3