Welcome Guest, Not a member yet? Register   Sign In
Help with datamapper database design and structure
#6

[eluser]North2Alaska[/eluser]
[quote author="Andy78" date="1334240557"]Based on the structure in the diagram how would I go about creating an order which has multiple food items in it and is related to a specific user and from a specific takeaway. How would I structure the save for all that in my controller?
[/quote]
Code:
$order = new Order();
//  Add other order information

$food = new Food();
$food->where('food_name', 'hamburger')->get();

$order->save($food);

$food = new Food();
$food->where('food_name', 'Soda')->get();

$order->save($food);

$food = new Food();
$food->where('food_name', 'French Fries')->get();

$order->save($food);
WanWizard may be able to tell us a way using an array and do the save all at once. But this is what I am doing now.

I just thought of something else:
Code:
$order = new Order();
//  Add other order information

$foods = array('hamburger', 'French Fries', 'Soda');
$food = new Food();
$food->where_in('food_name', $foods)->get();

$order->save($food->all);
That may work.


Messages In This Thread
Help with datamapper database design and structure - by El Forum - 04-11-2012, 08:01 AM
Help with datamapper database design and structure - by El Forum - 04-11-2012, 08:33 AM
Help with datamapper database design and structure - by El Forum - 04-11-2012, 08:45 AM
Help with datamapper database design and structure - by El Forum - 04-11-2012, 08:58 AM
Help with datamapper database design and structure - by El Forum - 04-12-2012, 07:22 AM
Help with datamapper database design and structure - by El Forum - 04-12-2012, 07:54 AM
Help with datamapper database design and structure - by El Forum - 04-12-2012, 10:38 AM
Help with datamapper database design and structure - by El Forum - 04-12-2012, 10:51 AM
Help with datamapper database design and structure - by El Forum - 04-12-2012, 11:04 AM
Help with datamapper database design and structure - by El Forum - 04-13-2012, 04:37 AM
Help with datamapper database design and structure - by El Forum - 04-13-2012, 07:36 AM
Help with datamapper database design and structure - by El Forum - 04-13-2012, 09:27 AM
Help with datamapper database design and structure - by El Forum - 04-13-2012, 10:34 AM
Help with datamapper database design and structure - by El Forum - 04-16-2012, 02:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB