I have created two tables as, forum_post and gallery.
forum_post table:
id user_id ststus photo_id
1 1 hi...! NULL
2 1 hello! NULL
3 1 NULL 1
4 1 NULL 2
user_gallery table:
id user_id image video
1 1 1.jpg NULL
2 1 new.gif NULL
When, user upload the image file in the user_gallery table, i want to create one row in the forum_post table and store the gallery id into the forum_post-> image field. as well as the user id also stored in the forum_post table.
My model code in the ForumPost is:
public static function addForumImage($id, $user_id) {
$forumImage = ForumPost::model()->find('LOWER(photo_id) = ?', array( strtolower($image)));
if (!$forumImage) {
$forumImage = new ForumPost;
$forumImage->photo_id = $image;
$forumImage->save(false);
}
UserGallery beforeSave function is:
protected function beforeSave() {
if (parent::beforeSave()) {
ForumPost::addForumImage($this->id, $this->user_id);
// var_dump($forumPost->photo_id);
return true;
}
return false;
}
My table relationship is, user_gallery->image refers the forum_post->photo_id.
Now, the image is stored in the user_gallery folder and i dint get the id in the ForumPost model... Please any one help me.. :(
try this
Model