$source = $url->getObject('source_'); debug($source, 'Source'); $session->set('relation_source', $source->getUid()); } elseif ($url->get('action')) { $source = $thinkedit->newObject($session->get('relation_source')); } else { echo translate('save_before_relating'); die; // todo more gracefull : do not display relation iframe iframe in edit when editing new record } $relation = new relation(); /*********** handle actions **********/ if ($url->get('action') == 'relate') { //echo 'I must relate'; $target = $url->getObject('target_'); $relation->relate($source, $target); } if ($url->get('action') == 'unrelate') { //echo 'I must relate'; $target = $url->getObject('target_'); $relation->unrelate($source, $target); } $relations = $relation->getRelations($source); if ($relations) { foreach ($relations as $relation_object) { $relation_object->load(); $item['title'] = te_short($relation_object->getTitle(), 50); $item['icon'] = $relation_object->getIcon(); $url->set('action', 'unrelate'); $url->addObject($relation_object, 'target_'); $item['remove_url'] = $url->render();
<?php require_once '../thinkedit.init.php'; require_once ROOT . '/class/relation.class.php'; $articles = $thinkedit->newRecord('article'); $authors = $thinkedit->newRecord('author'); // get first article $article = $articles->findFirst(); // get first author $author = $authors->findFirst(); $relation = new relation(); debug($article); debug($author); $relation->relate($article, $author); //$relation->unRelate($article, $author); $relations = $relation->getRelations($article); foreach ($relations as $related_item) { $related_item->load(); echo $related_item->getTitle(); } echo $total_queries;