Welcome Guest, Not a member yet? Register   Sign In
DataMapper - Counting related items
#8

[eluser]Anestetikas[/eluser]
I have a little bit different problem. Im just starting using datamapper.
Example:
tables:

Code:
bookshelfs(id, name)

books(id, bookshelf_id, title, pagecount)

poems(id, book_id, name, length...)

I want to list of bookshelfs:

Bookshelf number, bookCount, poemCount

As I imagine MVC and ci, i need to generate a list of bookshelfs and pass it to view, i do:

Code:
$shelfs = new Boookshelf();
$shelfs->include_related_count('book');

at this point everything is good, I can pass $shelfs to a view and with foreach loop I can output book_count as a number of books for shelf.

If i do
Quote:$shelfs->include_related_count('poem');

I get an error
Quote:Unable to relate bookshelf with poem.

In my bookshelf model:
Code:
$has_many = array('book');
book model:
Code:
$has_one = array('bookshelf');  $has_many = array('poem');
In poem model:
Code:
$has_one = array('book');

I can bypass this by starting to ->get() stuff in the view but its the wrong way to do it as I suppose.
My main goal is to show how many poems does the bookshelf contain. What am i missing here?



GOT IT !!!
This stuff is so awesome!
Did the wrong approach.


Messages In This Thread
DataMapper - Counting related items - by El Forum - 03-21-2011, 11:58 AM
DataMapper - Counting related items - by El Forum - 03-21-2011, 05:03 PM
DataMapper - Counting related items - by El Forum - 03-21-2011, 06:06 PM
DataMapper - Counting related items - by El Forum - 03-21-2011, 06:18 PM
DataMapper - Counting related items - by El Forum - 03-22-2011, 01:37 AM
DataMapper - Counting related items - by El Forum - 03-22-2011, 03:53 AM
DataMapper - Counting related items - by El Forum - 03-22-2011, 05:45 AM
DataMapper - Counting related items - by El Forum - 03-24-2011, 07:50 AM
DataMapper - Counting related items - by El Forum - 11-22-2012, 12:22 PM
DataMapper - Counting related items - by El Forum - 11-22-2012, 02:03 PM
DataMapper - Counting related items - by El Forum - 11-23-2012, 01:27 AM
DataMapper - Counting related items - by El Forum - 11-23-2012, 03:39 AM
DataMapper - Counting related items - by El Forum - 11-23-2012, 07:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB