Welcome Guest, Not a member yet? Register   Sign In
Null saved on field_id related with save method of Datamapper
#1

[eluser]Unknown[/eluser]
Hi people,

sorry my english i'm speak spanish,
I’ve start in Datamapper

i have a problem when i try save a object in table related

Code:
class Topic extends DataMapper {
public $has_many = array('answer');
    }

    class Answer extends DataMapper {
public $has_one = array('topic', 'user');
    }

    class Topics extends CI_Controller {

        public function newreply() {
    $tid = $this->input->post('tid');
    $msg = $this->input->post('msgbody');
  
    $a = new Answer();
    $a->trans_start();
    $a->content = $msg;
  
           $u = new User();
    $u->get_by_id(1);

    $t = new Topic();
    $t->get_by_id($tid);
      
    $a->save(array($t, $u));
    $a->trans_complete();
  
    $this->viewtopics($tid);
  }
     }

answer table structure

Code:
CREATE TABLE IF NOT EXISTS `answers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `content` longtext CHARACTER SET utf8 NOT NULL,
  `created` datetime NOT NULL,
  `topic_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `topic_id` (`topic_id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;


when i want save new reply for one topic in answer table, topics_id before inserted take a NULL value and the new reply is correct inserted with the topic_id gived...

WHAT IS WRONG IN MY FUNCTION?

thanks for your replies...




Theme © iAndrew 2016 - Forum software by © MyBB