Sunday, September 18, 2011

Re: Manual entry for habtm linking table.

Thanks Paul,

First time for me in Cake, normally use WP and Codeigniter but wanted
to try out the baking. I was trying to over complicate it with:

$db_data = array(
'teacher_id' => $teacher['Teacher']['id'],
'tclass_id' => $tclass['Tclass']['id']
);
$this->Teacher->TeachersTclasses->create();
$this->Teacher->TeachersTclasses-
>save($db_data);

but actually this just worked..

$this->Teacher->query("INSERT INTO teachers_tclasses
(tclass_id, teacher_id) VALUES
(".$tclass_id.", ".$teacher['Teacher']
['id'].");");

Cheers Chris


On Sep 16, 8:37 am, WebbedIT <p...@webbedit.co.uk> wrote:
> If using Cakes HABTM automagic the table should be named
> classes_teachers and have the following fields
>
> id (primary_key, auto_inc)
> class_id
> teacher_id
>
> After that it's a case of
> INSERT INTO classes_teachers (class_id, teacher_id) SELECT class_id,
> teacher_id FROM import_table
>
> HTH, Paul
> @phpMagpie
>
> On Sep 15, 9:24 pm, "porangi.chris" <porangi.ch...@gmail.com> wrote:
>
>
>
>
>
>
>
> > hi,
>
> > First time user of cake with CI background,  I have two tables
> > teachers and classes that share a many to many relationship e.g.
> > Teacher-Classes.
>
> > I'm having to import the data from CSV files that have been exported
> > from another system that we have limited access to.    I've got the
> > classes working - I can scan through the file and add the class if it
> > doesn't already exist but I need to add the links between class and
> > teacher.
>
> > I have an associative array with the two ids (tclass_id and
> > teacher_id) ready but what query call would I make to insert this as a
> > row in the teacher_class table?
>
> > Thanks in advance for any help.
>
> > Chris

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate