[eluser]Cgull[/eluser]
Hello,
I am new to using Datamapper and I can't understand it all, need some help.
I have these tables:
provinces:
id
name
books:
id
name
books_provinces:
id
book_id
province_id
Each book can have many provinces and each province can have many books.
I can create a province and I can create a book.
I have a page with the list of all the provinces and on it a button for books.
The button for books opens a page with a list of all the books the province is linked to.
Now I want to create a page where the user can add books to a province.
I tried using the htmlform extension but got totally lost.
So I create a form without the extension but I don't know how to limit the books list to books that are not already linked to the province.
My code for populating the books dropdown is:
Code:
$books = new Book();
$array = $books->get();
foreach($array as $arr)
{
$options[$arr->id] = $arr->name;
}
$this->data['books'] = $options;
Can someone plesae help?
This solved the problem I had in the second post (Adding another new book object for the not_in query):
Code:
$b = new Book();
// Get all books relating to the given province
$array = $b->where_related('province', 'id', $id)->get();
foreach($array as $a)
{
$names[] = $a->id;
}
$bb = new Book();// Solved the problem
$books = $bb->where_not_in('id', $names)->get();
foreach($books as $val)
{
$options[$val->id] = $val->name;
}