Saturday, August 4, 2012

cakePHP joining two tables

Im new to cakePHP and the whole table relations concept is very confusing!

I have 2 tables, competencies and competenceRatings. competencies stores a list of names with ids. 

    competencies
    ------------
    id
    name

And users can select various competencies from this table and rate them and their ratings are stored into competenceRatings table.

    competenceRatings
    -----------------
    id
    competence_id
    user_id
    rating

I want to be able to get the names of competencies for which a user have NOT made any ratings into competenceRatings table. i.e., I need list of names from competencies table for which there are no entries in comptenceRatings table(for given user_id).

I tried competencies->hasMany->competenceRatings, competenceRatings->belongsTo->competencies relations.


$competencies = $this->Competence->CompetenceRating->find('all',array('CompetenceRating.user_id' => $userId,'CompetenceRating.competence_id !=' => 'Competence.id'));

But no use!

Does this result require any other relations? Or can i just join tables using joins condition in find query?

Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: