Saving Data to the models

Hi dears,

I have the tables with fields as

Section

Section_id

Categorie

category_id

The relation of both of the tables is stored in another table

section_category_relation as

section_id,category_id

I want to save the section_id and category_id in the section_category_relation while creating the new category.

How to do that

I have the following code segment for it

in categorycontroller.php


  createAction(){

          $category=new Categories; // category model

          $section= new Sections ;//

}

How to save the section_id,category_id in the section_category_relation table?

Thanks

Create a model for the relation table… and you know all the rest :)




$relation= new RelationModel;   	// model of your relation (like section_category)

$relation.section_id=$section.id;

$relation.category_id=$category.id;

$relation->save();



Thanks dear, It works but with bit of modification




$relation= new RelationModel;   	// model of your relation (like section_category)

$relation['section_id']=$section.id;

$relation['category_id']=$category.id;

$relation->save();



I was typing too fast :), but as it’s an object you can use it as


$relation->section_id

at least for me it’s more readable than the array notation…

You are right.

Thanks