0

This is my error:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users_groupnames.id' in 'field list'

And the SQL Query:

SELECT `Groupname`.`id`, `Groupname`.`GroupName`, `Groupname`.`User_id`, 
       `UsersGroupname`.`id`, `users_groupnames`.`id`, `users_groupsnames`.`user_id`, 
       `users_groupnames`.`groupname_id` 
FROM `Cake-blog`.`groupnames` AS `Groupname` 
  JOIN `Cake-blog`.`users_groupnames` AS `UsersGroupname` 
   ON (`UsersGroupname`.`User_id` IN (1, 2, 4, 5, 6, 13, 14) 
   AND `UsersGroupname`.`Group_id` = `Groupname`.`id`)

Now here is the question: "Were I have a mistake?"

Model Groupname.php:

public $hasAndBelongsToMany = array(
        'User' =>
            array(
                'className' => 'User',
                'joinTable' => 'users_groupnames',
                'foreignKey' => 'Group_id',
                'associationForeignKey' => 'User_id'
            )
    );

And my User.php Model:

public $hasAndBelongsToMany = array(
        'Groupname' =>
            array(
                'className' => 'Groupname',
                'joinTable' => 'users_groupnames',
                'foreignKey' => 'User_id',
                'associationForeignKey' => 'Group_id'
            )
    );

My task is do the M:N relation in CakePHP to view next Groupname and Users.

My GroupnameController.php:

<?php
class GroupnameController extends AppController {
public function index() {
        $this->set('Groupnames', $this->Groupname->find('all')); //Načtení users z db do view
    }
}    
?>  
arilia
  • 9,373
  • 2
  • 20
  • 44

0 Answers0