user327712
user327712

Reputation: 3321

Tables relationship in Cakephp

I am new to Models structure in Cakephp.
A few weeks ago I came across a tutorial in which the author
got three tables in Database:

Table A: {ID, Description, IsActive}
Table B: {ID, TableA_ID, Description, CreationDate, ModifiedDate}
Table A_B: {ID, TableA_ID, TableB_ID}

The author of the tutorial said that the third table (Table A_B) is needed to
run in CakePHP.

I don't understand.
Is there any specific documentation in CakePHP that I can refer to?
I know there is a CookBook in Cakephp web site, but I couldn't find the
relevant infromation.

Upvotes: 1

Views: 596

Answers (2)

deceze
deceze

Reputation: 522597

"... the third table (Table A_B) is needed to run in CakePHP."

Table B already includes a foreign key TableA_id referencing table A, implying a belongsTo or "one-to-many" relationship. Table A_B implies a hasAndBelongsToMany or "many-to-many" relationship. It seems a bit nonsensical to have both. You would need a really specific reason for this. Unless the author mentions this reason, disregard his advice. :)

Upvotes: 4

Young
Young

Reputation: 8366

I guess what you need is HABTM in the cookbook.

Upvotes: 1

Related Questions