Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthortwentyeight
     
    I've done some digging on this, but with deadlines looming it's probably time to ask for help.

    I'm trying to paginate a listing of Parts. Each part has_many Photos. Pagination ostensibly works, but I'm missing something. What seems to be happening when I getPaginator() is the generated limit statement applies to the records retrieved from the database and not logical "Part" objects.

    For example, if each Part has 2 Photos, and there's 10 Parts, then 20 records will be returned. At 10 Parts per page, this yields the incorrect result of two pages with 5 Parts each. This wouldn't be terrible except that Parts may obviously have any number of Photos, and so in effect some parts get sucked into the void and never show up.

    I've tried looking into count_options and count_joins, but they don't seem to do what I'm looking for.

    Help?
    • CommentAuthorKaste
     

    don't know the paginator, never thought this thing worked.

    now it depends on what information you like to have in the view and what your sql-skills are;-)

    simple but with deadlines looming algorithm, two queries:

    1. try to get the ids of 'Parts'. thats a select distinct parts.id from parts limit 10, maybe with all joins, or a group by parts.id-clause
    2. do a normal ->find($found_ids_array,array(inlcude.etc...))

    thats the rails way.

    you can get it in one shot, but thats heavy sql-stuff.

    • CommentAuthortwentyeight
     
    This worked perfectly-- Thank you! I was trying to formulate the one-shot SQL and totally missed this. If anyone has the time it'd be interesting to see the concepts behind doing it all in one SQL statement.

    Thanks again, Kaste
    • CommentAuthorKaste
     

    basically you can

    select parts.* [...] from parts 
        left join photos on [...] [etc.]
        #finally
        join(
            select distinct photos.id from photos
            where ...
            order ...   
            limit ... 
            offset ... 
        ) as limiter on limiter.id = photos.id
     ;
    

    something like that, from the top of my head though