Welcome Guest, Not a member yet? Register   Sign In
DataMapper: does set_join_field() create a new record or only update an existing one?
#3

[eluser]Genki1[/eluser]
Thank you for confirming. For the benefit of others, here is the example from the manual (http://datamapper.wanwizard.eu/pages/joinfields.html) with my notes added:

Code:
// Create objects
$u = new User();
$u->get_by_id($userid);

$alarm = new Alarm();
$alarm->get_by_id($alarmid);

// relate the objects
$u->save($alarm);  // needed once only, not each time set_join_field() is called

// mark this alarm as fired
$alarm->set_join_field($u, 'wasfired', TRUE);  
// table has been updated; save() is not needed

I've had this question several times as I've started and stopped development and need to refresh my understanding of DM. It would be helpful if the example in the documentation noted:
(a) the need to establish the relationship before using set_join_field(), and
(b) no need for a save() after set_join_field()

Thanks again




Messages In This Thread
DataMapper: does set_join_field() create a new record or only update an existing one? - by El Forum - 05-12-2012, 09:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB