[eluser]prestondocks[/eluser]
Hi All,
I am getting the following error when running a query using datamapper
A Database Error Occurred
Error Number: 1054
Unknown column 'category_model_categorys_posts._id' in 'where clause'
SELECT `posts`.* FROM (`posts`) LEFT OUTER JOIN `categorys_posts` category_model_categorys_posts ON `posts`.`id` = `category_model_categorys_posts`.`_id` WHERE `category_model_categorys_posts`.`_id` IS NULL
I have a post_model and a category_model
Here is my category_model
Code:
class Category_model extends DataMapper
{
var $table = "categorys";
var $has_many = array('post');
var $validation = array(
'category'=>array(
'label'=>'Category',
'rules'=>array('required','min_legnth'=>3,'max_legnth'=>50),
),
'active'=>array(
'label'=>'Active',
'rules'=>array('required','valid_match'=>array(1,0)),
),
);
and here is my post_model and the function that is generating the error
Code:
class Post_model extends DataMapper
{
var $table = "posts";
var $has_one = array('user','category');
var $has_many = array('comment');
var $validation = array(
'title'=>array(
'label'=>'Title',
'rules'=>array('required','max_legnth'=>120,'min_legnth'=>5),
),
'body'=>array(
'label'=>'Post Body',
'rules'=>array('required','min_legnth'=>5),
),
'status'=>array(
'label'=>'Post Status',
'rules'=>array('required','valid_match'=>array(1,2,3)),
),
);
function get_by_category($category)
{
$c = new Category_model();
$c->get_where('category',$category);
$p = new Post_model();
$p->where_related($c);
$p->get();
return $p;
}
My database has a posts table, categorys table and categorys_posts table.
I am using the tip version of datamapper
Any help much appreciated.
Thanks
Simon