samotnik
samotnik

Reputation: 1

CakePHP makes a join between two models, but not between two others

I have four very simple models. Offer, Employer, Employee and Response.

Offer hasOne Employer
Employer hasMany Offer
Response hasOne Employee
Employee hasMany Offer

And now when I make a find() on Offer, it nicely makes a JOIN query and returns Employer details.

But when I make a find() on Response, it doesn't attempt to retrieve Employee's data.

I reviewed the code many times, stripped the models off of any additional properties etc., and still nothing. Those models are now nearly identical, their SQL tables too, but Response behaves like it has no relation to Employee defined.

Any pitfall with this that I might be trapped in? I'm ready to report this as a bug at this moment.

I can post complete (which are short, anyway) model definitions here if it helps anything.

Upvotes: 0

Views: 53

Answers (1)

AD7six
AD7six

Reputation: 66208

Check the class of your model instances

I.e.

debug(get_class($this->Response));

If it outputs AppModel - the reason your code doesn't appear to be being used, is because: it isn't being used. That being the case, check for typos in the filename/location of your model files - as CakePHP will silently use an AppModel instance if your model files don't exist.

Upvotes: 1

Related Questions