5
votes

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

1

1 Answers

6
votes

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.