Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cake bake model generation (hasOne vs hasMany)

I'm trying to get the 'cake bake' console command to generate 2 Models with a belongsTo/hasOne relationship (from the database schema) and it keeps generating a belongsTo/hasMany two-way relationship.

I am following the this guide on these definitions for the column name conventions ('user_id' in Profile, 'profile_id' in User) but, like I said, 'cake bake' keeps getting it wrong. Is 'cake bake' capable of determining the difference between hasOne and hasMany? Does anyone have a simple MySQL schema example where this is working? I'm using CakePHP 1.3.6

like image 782
phife757 Avatar asked Jan 04 '11 22:01

phife757


1 Answers

hasOne and hasMany relationships are identical from an SQL schema perspective, the difference is simply that there's an artificial restriction on the number of related records (1). bake can't tell the difference. If you're using the interactive process, it should suggest the more common hasMany relationship first, and the hasOne alternative second.

like image 145
deceze Avatar answered Oct 19 '22 01:10

deceze