Tuesday, April 5, 2011

Re: hasAndBelongsToMany gives server error in CakePHP 1.3

Error Message:
"An Internal Error Has Occurred
Error: An Internal Error Has Occurred."

No logs in errors and debug logs


This is the code:

Database:
CREATE TABLE`posts`(
`id`int(11) unsigned NOT NULL auto_increment,
`name` varchar(255) default NULL,
`date` datetime default NULL,
`content` text,
`user_id` int(11) default NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE`comments`(
`id`int(11) unsigned NOT NULL auto_increment,
`name` varchar(100) default NULL,
`content` text,
`post_id` int(11) default NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE`users`(
`id`int(11) unsigned NOT NULL auto_increment,
`name` varchar(100) default NULL,
`email` varchar(150) default NULL,
`firstname` varchar(60) default NULL,
`lastname` varchar(60) default NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `tags` (
`id`int(11) unsigned NOT NULL auto_increment,
`name` varchar(100) default NULL,
`longname` varchar(255) default NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `posts_tags` (
`id`int(11) unsigned NOT NULL auto_increment,
`post_id` int(11) unsigned default NULL,
`tag_id` int(11) unsigned default NULL,
PRIMARY KEY (`id`)
);


Files:
<?
class UsersController extends AppController {
var $name = 'Users';
var $scaffold;
}
?>
<?
class User extends AppModel {
var $name = 'User';
var $hasMany = array('Post');
}
?>
<?
class TagsController extends AppController {
var $name = 'Tags';
var $scaffold;
}
?>
<?
class Tag extends AppModel {
var $name = 'Tag';
var $hasAndBelongsToMany = array('Post');
}
?>
<?
class PostsController extends AppController {
var $name = 'Posts';
var $scaffold;
}
?>
<?
class Post extends AppModel {
var $name = 'Post';
var $belongsTo = array(
'User'=>array(
'className'=>'User',
'foreignKey'=>'user_id',
'conditions'=>null,
'fields'=>null
)
);
var $hasAndBelongsToMany = array('Tag');
}
?>
On Apr 5, 10:22 pm, cricket <zijn.digi...@gmail.com> wrote:
> On Tue, Apr 5, 2011 at 9:58 AM, Pankaj Agrawal <pankaj.visi...@gmail.com> wrote:
> > Hi,
>
> > I have tried alot of example as It like i am not able to find a
> > solution. Is there a problem in using hasAndBelongsToMany in CakePHP
> > 1.3 or is there any change from older versions because I am trying to
> > use it but it give Internal Server All the time. Even with direct book
> > examples.
>
> I don't think you will receive much of a response without posting at
> least the error message and the code that is triggering it.

--
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: