> If you mean that a user *hasAndBelongsToMany* submissions, and also a
> submission *hasAndBelongsToMany* users, I think you need a link table
> "users_submissions" to record the associations.

I _have_ the submissions_users table.

The HABTM association is working fine as long as I want to retrieve _all_
associated records ($this->Submission->findAll()).

However, I have a problem when I want to retrieve selected records based on
conditions in Model 2 (User).

In the meantime, I also tried it "from the other side", doing a findAll()
from the User table side:

$this->Submission->User->findAll(array('User.id' => 2));

This way, I get the desired records. However, the fundamental problem
remains (I didn't mention this in my first post as it was not relevant at
this time): I can't select records based on conditions in the "remote"
Model.

To make this clearer, here is a complete description of my setup:

class Submission extends AppModel
{
    var $belongsTo = array(
            'Contest' => array('className' => 'Contest')
    );

    var $hasAndBelongsToMany = array(
            'User' => array('className' => 'User')
    );

}


class User extends AppModel
{
    var $hasAndBelongsToMany = array(
            'Submission' => array('className' => 'Submission')
    );
}


And here is the custom query I wrote to select the desired records:

SELECT * FROM
    submissions AS Submission,
    submissions_users AS SU,
    users AS User, 
    contests as Contest
WHERE
    Submission.id = SU.submission_id AND
    User.id = SU.user_id AND
    User.id = 2 AND
    Submission.contest_id = Contest.id AND
    Contest.active = 1;

As you can see, there are conditions imposed on the Contest model and the
User model. 

When doing a $this->Submission->findAll(), I can't find records based on
conditions in the User Model.

When doing a $this->Submission->User->findAll(), I can't find records based
on conditions in the Contest Model.

Right now, it seems that a custom query (over 3 tables) is necessary to get
the desired result...

Thanks to everyone who took the time to answer :)

Heiner





> 
> 
> > 



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to