I don't think you have understood my question.

My concern is not that I have too many fields nor my field names. 

I am asking if there is an easy way to produce a data structure that lends 
itself to the output I want:

Foreach movie in movies
    print movie.title
    foreach stars in movie.stars
       print star.name



On Monday, August 13, 2012 6:47:13 PM UTC-4, Alec Taylor wrote:
>
> It sounds like you want to reduce the fields shown in the results, since 
> you already know some of the information.
>
> However the additional queries, though smaller, will require more 
> resources than a simple join. So I recommend just sticking with the join, 
> and displaying in your view what you'd like.
>
> As for the wrapper to give things easier to work with names, just specify 
> said information in your controller.
> On 14/08/2012 8:04 AM, "Mike Girard" <[email protected] <javascript:>> 
> wrote:
>
>> I have a movie table that has a many-to-many relationship with a person 
>> table expressed through a star table.
>>
>> A simplified version of my model:
>>
>> db.define_table('movie',
>>
>>     Field('title','string'),
>>
>>  db.define_table('person', 
>>
>>      Field('name', 'string', unique=True),
>>
>> db.define_table('star', 
>>
>>      Field('movie_id', db.movie),
>>
>>      Field('person_id', db.person),
>>
>> I am able to create a select that joins the three tables and produces a 
>> result with all the data I need.
>>
>> It's easy to iterate through the result and produce something akin to 
>> this:
>>
>> Movie Title  Star 1
>>
>> Movie Title  Star 2
>>
>> Movie Title  Star 3
>>
>>
>> What I want is:
>>
>> Movie Title 1
>>
>> Star 1, Star 2, Star 3
>>
>>
>> Movie Title 2
>>
>> Star 1, Star 2, Star 3
>>
>>
>> Programmatically, I'd like something like:
>>
>> for each movie in rows
>>
>>     <h2>move.title</h2>
>>
>>      <ul>
>>
>>       for each star in movie.stars
>>
>>       <li>star.name</li>
>>
>>
>> Before I write a function to pre-process the result, can someone tell me 
>> if there is a helper for producing a result of this kind? 
>>
>> This thread addresses the same issue - 
>>
>> https://groups.google.com/forum/?fromgroups#!topic/web2py/GQsMt4qvqSs
>>
>> - but I was unable to discern the solution the question asker had 
>> produced for himself, the key to which was this:
>>
>> "web2py automatically add the many-to-many sets to an instance with the 
>>
>> same name of the relation table"
>>
>> I do not know what that means. 
>>
>> -- 
>>  
>>  
>>  
>>
>

-- 



Reply via email to