I love how I can just use
$book->import( $_POST );
to import the POST data generated by my HTML form.
Only problem is that it doesn't seem to work if I have checkboxes in my form that are for a many-to-many relationship.
Ex:
<input name="title" />
<input type="checkbox" name="category[]" value="1" />
<input type="checkbox" name="category[]" value="2" />
<input type="checkbox" name="category[]" value="3" />
<input type="checkbox" name="category[]" value="4" />
On the server side, if I receive the data like this:
$book->import( $_POST );
I get an error.
What I'm hoping for is a category_book table to be populated.
Is there a way to do this with import()?
Or do I have to do it like this:
$book = R::dispense('book');
$book->title = $_POST['title']
foreach($_POST['category'] as $category_id) {
$category = R::dispense('category');
$category->id = $category_id;
$book->sharedCategoryList[] = $category;
}
R::store( $book );