CodeIgniter Forums
DataMapper Join Table with extra fields - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper Join Table with extra fields (/showthread.php?tid=48105)



DataMapper Join Table with extra fields - El Forum - 01-04-2012

[eluser]drakeonfire[/eluser]
Hello!

I'm trying to save relationships in a join table (Which is working woo!) but the problem is this join table has extra information, for example I have an Ingredients table and a Recipe table. the join table is ingredients_recipes and it contains:
id, ingredient_id, recipe_id, amount, unit_id

However when I try and save this, the amount and unit_id get left as 0 or NULL, even though I'm passing it the data. The bit where I'm doing this is:
Code:
$recipe = new Recipe();
$recipe->where('title',$title)->get();
$recipe_id = $recipe->id;
foreach($ing_rows AS $row) {
  $r = new Recipe($recipe_id);
  $r->amount = $row['amount'];
  $r->unit_id = $row['unit'];
  $i = new Ingredient($row['ing']);
  $r->save($i);
}

Any ideas? Sorry if this is a newb question, but from searching I couldn't find anything of help, or from the guide book.

Thank you!