public static function sync($r) { $match = array('subject_service' => $r['subject_service'], 'subject_type' => $r['subject_type'], 'subject_id' => $r['subject_id'], 'relation_type' => $r['relation_type'], 'object_service' => $r['object_service'], 'object_type' => $r['object_type'], 'object_id' => $r['object_id']); $relations = EntityRelation::load_match($match); if (empty($relations[0])) { // create $id = EntityRelation::create($r); } else { // sync $relations[0]->update($r); $id = $relations[0]->id; } return $id; }