Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple foreign keys to the same table in Cake PHP?

Tags:

sql

php

orm

cakephp

Cake has its conventions for automating some functionality interaction between it's models and the tables they reference. Foreign keys should be called people_id, if they reference a table called people. How do I handle a case where a row holds two people, and needs foreign keys for both people? It's obvious that I can't duplicate the column names, having two people_id columns.

Consider a competition where you have two competitors. Each competitor is represented by a row in the competitor's table. The competitions table needs to refer to both of those competitors. How can I do this wouldn't breaking the automatic functionality that Cake offers?

like image 391
Adam Avatar asked Mar 09 '26 12:03

Adam


1 Answers

I found a link that describes how to do this perfectly.

http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm

like image 185
Adam Avatar answered Mar 11 '26 01:03

Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!