OK I've now worked out 100% what my problem was!

The problem was because my two Models (vote & user) were using
$hasAndBelongsToMany  they did not have to have the Full classname in,
for instance:

class User extends AppModel
{
    var $name = 'User';
         var $hasAndBelongsToMany = array(
        'UserVote' => array(
                'className' => 'UserVote',
                'foreignKey' => 'user_id',
                'dependent' => true
        )
    );
}



And I changed this to---

class User extends AppModel
{
    var $name = 'User';
         var $hasAndBelongsToMany = array(
        'User' => array(
                'className' => 'User',
                'foreignKey' => 'user_id',
                'dependent' => true
        )
    );
}

And it worked. That was the answer!


On Jun 12, 11:36 am, Andrew <[email protected]> wrote:
> Thank you.
> After many different tries I ended up renaming my table to user_votes
> and everything seemed to work at last.
>
> It does get confusing!
>
> On Jun 12, 10:01 am, Dima <[email protected]> wrote:
>
>
>
> > You can include the following in your model to specify the name of the
> > table to use if you do not want to follow Cake's naming convention.
> > Try this:
>
> > [code]
> > var $useTable = <your table name>;
> > [/code]
>
> > So your model will look something like this:
>
> > [code]
> > class User extends AppModel
> > {
> >    var $name = 'User';
> >    var $useTable = 'user_votes';
> >    var $hasAndBelongsToMany = array(
> >       'UserVote' => array(
> >          'className' => 'UserVote',
> >          'foreignKey' => 'user_id',
> >          'dependent' => true
> >       )
> >    );}
>
> > [/code]
>
> > Hope this helps,
> > Dima
>
> > On Jun 11, 4:55 pm, Ed Propsner <[email protected]> wrote:
>
> > > All of my underscored table names work just fine, but this is something I
> > > wonder about:
>
> > > If both parts of the underscored table name are plural (users_votes) ..
> > > would the model be UsersVote or UserVote. Do both parts get singularized?
>
> > > In any case, your issue still seems to be with naming conventions.
>
> > > - Ed
>
> > > On Fri, Jun 11, 2010 at 5:43 PM, Jonathon Musters 
> > > <[email protected]>wrote:
>
> > > > I think the new table should be called UsersVotes. No underscore.
>
> > > > On 6/11/10, Andrew <[email protected]> wrote:
> > > > > Hello all,
>
> > > > > I've been using cakephp for a few months now and I love it!! I must
> > > > > admit I am still getting used to some of the concepts. At the moment
> > > > > I'm trying to add a database bridging table for a HasAndBelongsToMany
> > > > > Model. My three models involved are Users, Votes and Users_Votes.
>
> > > > > So when I call the view /users_votes/create/ I get the error message
>
> > > > > Missing Database Table
> > > > > Error: Database table user_votes for model UserVote was not found.
> > > > > Notice: If you want to customize this error message, create app/views/
> > > > > errors/missing_table.ctp
>
> > > > > I am using Cakephp 1.3.
>
> > > > > - My database names are Users, Votes and Users_Votes
> > > > > - My model names are user, vote, and uservote
> > > > > - I think I have my models correct
>
> > > > > class User extends AppModel
> > > > > {
> > > > >     var $name = 'User';
>
> > > > >        var $hasAndBelongsToMany = array(
> > > > >         'UserVote' => array(
> > > > >                 'className' => 'UserVote',
> > > > >                 'foreignKey' => 'user_id',
> > > > >                 'dependent' => true
> > > > >         )
> > > > >     );
> > > > > }
>
> > > > > class UserVote extends AppModel
> > > > > {
> > > > >     var $name = 'UserVote';
>
> > > > >       var $belongsTo = array
> > > > >       (
> > > > >         'Vote' => array
> > > > >               (
> > > > >                'className'  => 'Vote',
> > > > >                'foreignKey' => 'id'
> > > > >         )
> > > > >     );
> > > > > }
>
> > > > > class Vote extends AppModel
> > > > > {
> > > > >     var $name = 'Vote';
>
> > > > >       var $hasAndBelongsToMany = array
> > > > >       (
> > > > >         'UserVote' => array(
> > > > >                 'className' => 'UserVote',
> > > > >                 'foreignKey' => 'vote_id',
> > > > >                               'dependent' => true
> > > > >         )
> > > > >     );
> > > > > }
>
> > > > > Thanks!
>
> > > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > > > others
> > > > > with their CakePHP related questions.
>
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups
> > > > > "CakePHP" group.
> > > > > To post to this group, send email to [email protected]
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<cake-php%[email protected]
> > > > >  om>For more options, visit this group at
> > > > >http://groups.google.com/group/cake-php?hl=en
>
> > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers
> > > > with their CakePHP related questions.
>
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "CakePHP" group.
> > > > To post to this group, send email to [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<cake-php%[email protected]
> > > >  om>For more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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?hl=en

Reply via email to