Skip to content

Instantly share code, notes, and snippets.

@vojtech-dobes
Created March 5, 2011 19:58
Show Gist options
  • Save vojtech-dobes/856666 to your computer and use it in GitHub Desktop.
Save vojtech-dobes/856666 to your computer and use it in GitHub Desktop.
Articles and categories used in example have many-to-many relation
<?php
# low-level
$feanorm->relate($article)->to($category)->on('categories');
$feanorm->unrelate($article)->to($category)->on('categories');
// The clause 'on' shouldn't be neccessary when only one relation between entities is present.
# practical api
$article->categories->add($category);
$article->categories->remove($category);
# practical api should accept all kinds of staff (and support lazy definition so)
$article->categories->add(1);
$article->categories->remove(3);
$article->categories->add($category1, $category2);
$article->categories->add($categories); // Collection
// choose better, but only one
$article->categories->remove('all');
$article->categories->empty();
$article->categories->clear();
# limitless possibilities
$article->categories->remove()->where('name')->like('A%');
$article->categories->add()->where('name')->like('A%'); // even this should be possible (API rules)
// means relate all categories beginning with letter 'A' to article
// this will never support lazy loading
$article->categories->remove(function($category) { return $category->isOld(); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment