[eluser]thomasjonas[/eluser]
Hello there,
I'm new to Datamapper and I'm straight diving into the advanced relations. Unfortunately it's not working out so great for me... Somehow I keep getting this error:
Code:
Unknown column 'User' in 'field list'
INSERT INTO `posts` (`title`, `creator`, `editor`) VALUES ('testing', User, User)
Filename: ........................../libraries/Datamapper.php
Line Number: 1724
I'm using CI 2.1.0
This is how my User model looks like:
Code:
class User extends DataMapper {
var $has_many = array(
'created_post' => array(
'class' => 'post',
'other_field' => 'creator'
),
'edited_post' => array(
'class' => 'post',
'other_field' => 'editor'
)
);
var $validation = array(
'username' => array(
'label' => 'Username',
'rules' => array('required', 'trim', 'unique', 'alpha_dash', 'min_length' => 3, 'max_length' => 20),
),
'password' => array(
'label' => 'Password',
'rules' => array('required', 'min_length' => 6, 'encrypt'),
),
'email' => array(
'label' => 'Email Address',
'rules' => array('required', 'trim', 'valid_email')
)
);
}
Post model
Code:
class Post extends DataMapper {
var $has_one = array(
'creator' => array(
'class' => 'user',
'other_field' => 'created_post'
),
'editor' => array(
'class' => 'user',
'other_field' => 'edited_post'
)
);
var $validation = array(
'title' => array(
'label' => 'Title',
'rules' => array('required')
)
);
}
Controller
Code:
$u = new User(1);
$p = new Post();
$p->title = "testing";
$p->save_creator($u);
$p->save();
In my database there already is a user with id=1
Database:
users:
-id
-username
-password
-email
posts:
-id
-title
-creator
-editor
posts_users
-id
-creator_id
-created_post_id
-editor_id
-edited_post_id
Hopefully it's a really stupid mistake that can be fixed easily...
Thanks in advance!