这是我的多对多关系
class Post extends ActiveRecord\Model {
static $table_name = 'app_post';
static $has_many = array(
array('postcategory'),
array('category', 'through' => 'postcategory')
);
}
class Category extends ActiveRecord\Model {
static $table_name = 'app_post_category';
static $has_many = array(
array('post', 'through' => 'postcategory'),
array('postcategory')
);
}
class PostCategory extends ActiveRecord\Model {
static $table_name = 'app_post_category_relation';
static $belongs_to = array(
array('post'),
array('category')
);
}
要在帖子中创建新记录,请使用
$post = Post::create(
array(
'title' => 'Title',
'description' => 'Description',
'keyword' => 'key,word'
)
);
$post->create_postcategory(array('category_id' => '1'));
$post->create_postcategory(array('category_id' => '3'));
但我不知道如何更新此记录?
$post = Post::find(1);
$post->title = 'Some title';
$post->save();
这只是更新帖子表关系表怎么样?