0

I'm new to CodeIgniter and ORM, I hope you guys can help me with this.

The question table:

CREATE TABLE `question` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(128) NOT NULL DEFAULT '',
  `content` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The answer table:

CREATE TABLE `answer` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `question_id` int(11) unsigned NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `question_id` (`question_id`),
  CONSTRAINT `answer_ibfk_1` FOREIGN KEY (`question_id`) REFERENCES `question` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The equivalent SQL is:

INSERT INTO answer(content, question_id) 
VALUES('Ironman', (select id 
                     from question 
                    where title ='favourite characters' 
                      and content = 'Who is your favourite characters in Avanger?'));

Anyone can tell me how to achieve the same thing but using CodeIgniter Activerecord?

mko
  • 21,334
  • 49
  • 130
  • 191

1 Answers1

0

Don't do that, instead use the primary key (id) to insert directly into the base table.

Ben
  • 34,935
  • 6
  • 74
  • 113
  • I have the same problem can u pls show how to do it. For my question you can refer http://stackoverflow.com/questions/13133730/convert-a-multiple-table-query-into-active-record-codeigniter – asifa Oct 30 '12 at 06:53