Skip to content

Instantly share code, notes, and snippets.

@jmertic
Created November 6, 2013 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmertic/7336266 to your computer and use it in GitHub Desktop.
Save jmertic/7336266 to your computer and use it in GitHub Desktop.
<?php
function link_record_beans($bean1, $bean2){
$m1 = $bean1->module_dir;
$m2 = $bean2->module_dir;
$rel=getRelationshipByModules($m1, $m2); //see link to previous post for this function
if($rel !== FALSE){
if($rel[1] == $m1){
$class = $bean1->object_name;
$id = $bean1->id;
$rel_id = $bean2->id;
}elseif($rel[1] == $m2){
$class = $bean2->object_name;
$id = $bean2->id;
$rel_id = $bean1->id;
}
$lhs = new $class;
$lhs->retrieve($id);
$lhs->load_relationship($rel[0]);
$lhs->$rel[0]->add($rel_id);
$lhs->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment