[web2py] Re: Problem with MANY-MANY relationship

2010-04-09 Thread Ishbir
That seems to be a good idea... I would love to see this in the next
release.

On Apr 8, 9:41 pm, Thadeus Burgess  wrote:
> Ive sent emails on the list twice, and one email to you personally
> about this. I have not implemented it since it never received any
> feedback.
>
> There will be a 'pre' and 'post' of 'select', 'insert', 'update',
> 'delete', separated by an underscore.
>
> The dal will maintain a list of functions for each of these. The
> function will be executed in order of assignment.
>
> So
>
> db.register('post_delete', copyRecordFunc)
> db.register('post_delete', notifyByEmail)
>
> In the dal.py it will look like
>
> results = self._cursor.execute('blah')
> for f in self.signals['post_delete']:
>    f(results)
>
> -Thadeus
>
> On Thu, Apr 8, 2010 at 10:59 AM, mdipierro  wrote:
> > y have missed or forgotten about this. I would be in favor
> > of this but I would like to see a complete naming scheme and
> > understand how do you handle the case when two functions are regitered
> > for the same function. How do you han


Re: [web2py] Re: Problem with MANY-MANY relationship

2010-04-08 Thread Thadeus Burgess
Ive sent emails on the list twice, and one email to you personally
about this. I have not implemented it since it never received any
feedback.

There will be a 'pre' and 'post' of 'select', 'insert', 'update',
'delete', separated by an underscore.

The dal will maintain a list of functions for each of these. The
function will be executed in order of assignment.

So

db.register('post_delete', copyRecordFunc)
db.register('post_delete', notifyByEmail)

In the dal.py it will look like

results = self._cursor.execute('blah')
for f in self.signals['post_delete']:
   f(results)

-Thadeus





On Thu, Apr 8, 2010 at 10:59 AM, mdipierro  wrote:
> y have missed or forgotten about this. I would be in favor
> of this but I would like to see a complete naming scheme and
> understand how do you handle the case when two functions are regitered
> for the same function. How do you han

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-08 Thread mdipierro
On Apr 8, 10:50 am, Thadeus Burgess  wrote:
> I have proposed a signal/slot system for the new DAL.

when? I may have missed or forgotten about this. I would be in favor
of this but I would like to see a complete naming scheme and
understand how do you handle the case when two functions are regitered
for the same function. How do you handle the order?

> Simply, The DAL provides an interface to "register" functions for
> common operations, such as select/insert/update/delete.
>
> You will simply
>
> db.register('pre_delete', myFunc)
> db.register('post_delete', myFunc)
>
> The only difference is when myFunc is called, pre hands the query over
> to the function, whereas post hands the results to the function. There
> is also a "on_delete" that is the same as "post_delete", just
> providing a more natural syntax.
>
> -Thadeus
>
> On Thu, Apr 8, 2010 at 5:55 AM, DenesL  wrote:
> > Except from being less verbose, how is this different from calling
> > somefunc under form.accepts?
>
> > form=SQLFORM(...) # create, update or delete
> > if form.accepts(...):
> >  somefunc(...)
>
> > On Apr 8, 5:34 am, Ishbir  wrote:
> >> The way that you are doing it in crud, do the same way in DAL. The
> >> only difference that create_onaccept function will be called if
> >> db.table.insert() is called whether directly or indirectly (via a crud
> >> form for e.g.) and the same applies for update and delete.
>
> >> In db.py, it could be something like-
>
> >> db.table.create_onaccept = somefunc
>
> >> where somefuc is a function in the form of-
>
> >> def somefunc(record_inserted):
> >>     # increment/decrement something here
> >>     pass
>
> >> What do you think?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "web2py-users" group.
> > To post to this group, send email to web...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > web2py+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: Problem with MANY-MANY relationship

2010-04-08 Thread Thadeus Burgess
I have proposed a signal/slot system for the new DAL.

Simply, The DAL provides an interface to "register" functions for
common operations, such as select/insert/update/delete.

You will simply

db.register('pre_delete', myFunc)
db.register('post_delete', myFunc)

The only difference is when myFunc is called, pre hands the query over
to the function, whereas post hands the results to the function. There
is also a "on_delete" that is the same as "post_delete", just
providing a more natural syntax.


-Thadeus





On Thu, Apr 8, 2010 at 5:55 AM, DenesL  wrote:
> Except from being less verbose, how is this different from calling
> somefunc under form.accepts?
>
> form=SQLFORM(...) # create, update or delete
> if form.accepts(...):
>  somefunc(...)
>
>
> On Apr 8, 5:34 am, Ishbir  wrote:
>> The way that you are doing it in crud, do the same way in DAL. The
>> only difference that create_onaccept function will be called if
>> db.table.insert() is called whether directly or indirectly (via a crud
>> form for e.g.) and the same applies for update and delete.
>>
>> In db.py, it could be something like-
>>
>> db.table.create_onaccept = somefunc
>>
>> where somefuc is a function in the form of-
>>
>> def somefunc(record_inserted):
>>     # increment/decrement something here
>>     pass
>>
>> What do you think?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to 
> web2py+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/web2py?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-08 Thread DenesL
Except from being less verbose, how is this different from calling
somefunc under form.accepts?

form=SQLFORM(...) # create, update or delete
if form.accepts(...):
  somefunc(...)


On Apr 8, 5:34 am, Ishbir  wrote:
> The way that you are doing it in crud, do the same way in DAL. The
> only difference that create_onaccept function will be called if
> db.table.insert() is called whether directly or indirectly (via a crud
> form for e.g.) and the same applies for update and delete.
>
> In db.py, it could be something like-
>
> db.table.create_onaccept = somefunc
>
> where somefuc is a function in the form of-
>
> def somefunc(record_inserted):
>     # increment/decrement something here
>     pass
>
> What do you think?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-08 Thread Ishbir
The way that you are doing it in crud, do the same way in DAL. The
only difference that create_onaccept function will be called if
db.table.insert() is called whether directly or indirectly (via a crud
form for e.g.) and the same applies for update and delete.

In db.py, it could be something like-

db.table.create_onaccept = somefunc

where somefuc is a function in the form of-

def somefunc(record_inserted):
# increment/decrement something here
pass

What do you think?

On Apr 7, 7:13 pm, mdipierro  wrote:
> Right now the DAL does not provide it because the goal is to keep it
> as close as possible to SQL layer. Nevertheless you have a good point
> and I would like to see a few proposals for possible API extension.
>
> On Apr 7, 5:33 am, Ishbir  wrote:
>
> > What you mentioned is only for crud forms. Isn't there anything like a
> > database wide on add/remove/update function definition? If no, don't
> > you think it would be good to implement it? For e.g. say I have tags
> > and tag count. I want to increment tag count on each post update/
> > addition/removal. That would be the most suitable option...
>
> > On Apr 6, 6:24 pm, mdipierro  wrote:
>
> > > This can only be done if insert and delete is done via crud.
>
> > > crud.settings.create_onaccept = f
> > > crud.settings.update_onaccept = f
> > > crud.settings.delete_onaccept = f
>
> > > where f is any function that takes the submitted form.
>
> > > On Apr 6, 5:34 am, Ishbir  wrote:
>
> > > > Thanks for your help, although I had to tweak the code to get it
> > > > working. It finally works! Thank you.
>
> > > > And by the way, do you know any way by which behaviours can be
> > > > defined? For e.g. if a record is added, then do something, if record
> > > > is deleted then do something. Can stuff like that be implemented in
> > > > web2py?
>
> > > > On Apr 5, 8:37 pm, Thadeus Burgess  wrote:
>
> > > > > Your join is performing a union, your queries could (and will) get
> > > > > quite huge, since your getting a record for every tag. (so for two
> > > > > tags you actually get two rows for that snippet). A left join will
> > > > > provide you with everything, but you still get a row for every tag.
>
> > > > > Even with a left join you will still have to query for the title of 
> > > > > the tag
>
> > > > > >>> rows = db().select(db.snippets.ALL, db.snippet_tags_link.ALL, 
> > > > > >>> left=db.snippet_tags_link.on(db.snippets.id == 
> > > > > >>> db.snippet_tags_link.snippet_id))
> > > > > >>> print rows
>
> > > > > snippets.id,snippets.title,snippets.content,snippets.created,snippet_tags_link.id,snippet_tags_link.snippet_id,snippet_tags_link.tag_id
> > > > > 1,hi,hello world,2010-04-05 09:21:20,1,1,1
> > > > > 1,hi,hello world,2010-04-05 09:21:20,2,1,1
> > > > > 2,woot,erifica,2010-04-05 09:21:20,,,
>
> > > > > Or you can do a secondary query to get the tags.
>
> > > > > snippets = db().select()
> > > > > for snip in snippets:
> > > > >    print snippet.title
> > > > >    for tag in snip.snippet_tags_link.select():
> > > > >       print tag.snippet_tags.name
>
> > > > > -Thadeus
>
> > > > > On Mon, Apr 5, 2010 at 8:46 AM, Ishbir  wrote:
> > > > > > I've got some problem with the MANY-MANY relation in Web2Py. This is
> > > > > > my code-
>
> > > > > >http://pastie.textmate.org/903738
>
> > > > > > Now, the problem is that the query returns only those records which
> > > > > > have tags, not the ones without them. However, if I specify query|
> > > > > > db.snippets.id>0 or anything, it gives me garbled results with all 
> > > > > > the
> > > > > > tables mixed up and nothing right..
>
> > > > > > Is there any way around this? I thought about using the tagging 
> > > > > > plugin
> > > > > > but the issue is that I don't think it would be very efficient 
> > > > > > since I
> > > > > > need to also display the tags on the index page and that would 
> > > > > > result
> > > > > > in n+1 queries where n is the no. of snippets. Or I am just getting
> > > > > > apprehensive and it will just take 2-3 queries to get the tags of
> > > > > > snippet?
>
> > > > > > --
> > > > > > You received this message because you are subscribed to the Google 
> > > > > > Groups "web2py-users" group.
> > > > > > To post to this group, send email to web...@googlegroups.com.
> > > > > > To unsubscribe from this group, send email to 
> > > > > > web2py+unsubscr...@googlegroups.com.
> > > > > > For more options, visit this group 
> > > > > > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-07 Thread mdipierro
Right now the DAL does not provide it because the goal is to keep it
as close as possible to SQL layer. Nevertheless you have a good point
and I would like to see a few proposals for possible API extension.

On Apr 7, 5:33 am, Ishbir  wrote:
> What you mentioned is only for crud forms. Isn't there anything like a
> database wide on add/remove/update function definition? If no, don't
> you think it would be good to implement it? For e.g. say I have tags
> and tag count. I want to increment tag count on each post update/
> addition/removal. That would be the most suitable option...
>
> On Apr 6, 6:24 pm, mdipierro  wrote:
>
> > This can only be done if insert and delete is done via crud.
>
> > crud.settings.create_onaccept = f
> > crud.settings.update_onaccept = f
> > crud.settings.delete_onaccept = f
>
> > where f is any function that takes the submitted form.
>
> > On Apr 6, 5:34 am, Ishbir  wrote:
>
> > > Thanks for your help, although I had to tweak the code to get it
> > > working. It finally works! Thank you.
>
> > > And by the way, do you know any way by which behaviours can be
> > > defined? For e.g. if a record is added, then do something, if record
> > > is deleted then do something. Can stuff like that be implemented in
> > > web2py?
>
> > > On Apr 5, 8:37 pm, Thadeus Burgess  wrote:
>
> > > > Your join is performing a union, your queries could (and will) get
> > > > quite huge, since your getting a record for every tag. (so for two
> > > > tags you actually get two rows for that snippet). A left join will
> > > > provide you with everything, but you still get a row for every tag.
>
> > > > Even with a left join you will still have to query for the title of the 
> > > > tag
>
> > > > >>> rows = db().select(db.snippets.ALL, db.snippet_tags_link.ALL, 
> > > > >>> left=db.snippet_tags_link.on(db.snippets.id == 
> > > > >>> db.snippet_tags_link.snippet_id))
> > > > >>> print rows
>
> > > > snippets.id,snippets.title,snippets.content,snippets.created,snippet_tags_link.id,snippet_tags_link.snippet_id,snippet_tags_link.tag_id
> > > > 1,hi,hello world,2010-04-05 09:21:20,1,1,1
> > > > 1,hi,hello world,2010-04-05 09:21:20,2,1,1
> > > > 2,woot,erifica,2010-04-05 09:21:20,,,
>
> > > > Or you can do a secondary query to get the tags.
>
> > > > snippets = db().select()
> > > > for snip in snippets:
> > > >    print snippet.title
> > > >    for tag in snip.snippet_tags_link.select():
> > > >       print tag.snippet_tags.name
>
> > > > -Thadeus
>
> > > > On Mon, Apr 5, 2010 at 8:46 AM, Ishbir  wrote:
> > > > > I've got some problem with the MANY-MANY relation in Web2Py. This is
> > > > > my code-
>
> > > > >http://pastie.textmate.org/903738
>
> > > > > Now, the problem is that the query returns only those records which
> > > > > have tags, not the ones without them. However, if I specify query|
> > > > > db.snippets.id>0 or anything, it gives me garbled results with all the
> > > > > tables mixed up and nothing right..
>
> > > > > Is there any way around this? I thought about using the tagging plugin
> > > > > but the issue is that I don't think it would be very efficient since I
> > > > > need to also display the tags on the index page and that would result
> > > > > in n+1 queries where n is the no. of snippets. Or I am just getting
> > > > > apprehensive and it will just take 2-3 queries to get the tags of
> > > > > snippet?
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups "web2py-users" group.
> > > > > To post to this group, send email to web...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to 
> > > > > web2py+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group 
> > > > > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-07 Thread Ishbir
What you mentioned is only for crud forms. Isn't there anything like a
database wide on add/remove/update function definition? If no, don't
you think it would be good to implement it? For e.g. say I have tags
and tag count. I want to increment tag count on each post update/
addition/removal. That would be the most suitable option...

On Apr 6, 6:24 pm, mdipierro  wrote:
> This can only be done if insert and delete is done via crud.
>
> crud.settings.create_onaccept = f
> crud.settings.update_onaccept = f
> crud.settings.delete_onaccept = f
>
> where f is any function that takes the submitted form.
>
> On Apr 6, 5:34 am, Ishbir  wrote:
>
> > Thanks for your help, although I had to tweak the code to get it
> > working. It finally works! Thank you.
>
> > And by the way, do you know any way by which behaviours can be
> > defined? For e.g. if a record is added, then do something, if record
> > is deleted then do something. Can stuff like that be implemented in
> > web2py?
>
> > On Apr 5, 8:37 pm, Thadeus Burgess  wrote:
>
> > > Your join is performing a union, your queries could (and will) get
> > > quite huge, since your getting a record for every tag. (so for two
> > > tags you actually get two rows for that snippet). A left join will
> > > provide you with everything, but you still get a row for every tag.
>
> > > Even with a left join you will still have to query for the title of the 
> > > tag
>
> > > >>> rows = db().select(db.snippets.ALL, db.snippet_tags_link.ALL, 
> > > >>> left=db.snippet_tags_link.on(db.snippets.id == 
> > > >>> db.snippet_tags_link.snippet_id))
> > > >>> print rows
>
> > > snippets.id,snippets.title,snippets.content,snippets.created,snippet_tags_link.id,snippet_tags_link.snippet_id,snippet_tags_link.tag_id
> > > 1,hi,hello world,2010-04-05 09:21:20,1,1,1
> > > 1,hi,hello world,2010-04-05 09:21:20,2,1,1
> > > 2,woot,erifica,2010-04-05 09:21:20,,,
>
> > > Or you can do a secondary query to get the tags.
>
> > > snippets = db().select()
> > > for snip in snippets:
> > >    print snippet.title
> > >    for tag in snip.snippet_tags_link.select():
> > >       print tag.snippet_tags.name
>
> > > -Thadeus
>
> > > On Mon, Apr 5, 2010 at 8:46 AM, Ishbir  wrote:
> > > > I've got some problem with the MANY-MANY relation in Web2Py. This is
> > > > my code-
>
> > > >http://pastie.textmate.org/903738
>
> > > > Now, the problem is that the query returns only those records which
> > > > have tags, not the ones without them. However, if I specify query|
> > > > db.snippets.id>0 or anything, it gives me garbled results with all the
> > > > tables mixed up and nothing right..
>
> > > > Is there any way around this? I thought about using the tagging plugin
> > > > but the issue is that I don't think it would be very efficient since I
> > > > need to also display the tags on the index page and that would result
> > > > in n+1 queries where n is the no. of snippets. Or I am just getting
> > > > apprehensive and it will just take 2-3 queries to get the tags of
> > > > snippet?
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "web2py-users" group.
> > > > To post to this group, send email to web...@googlegroups.com.
> > > > To unsubscribe from this group, send email to 
> > > > web2py+unsubscr...@googlegroups.com.
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-06 Thread mdipierro
This can only be done if insert and delete is done via crud.

crud.settings.create_onaccept = f
crud.settings.update_onaccept = f
crud.settings.delete_onaccept = f

where f is any function that takes the submitted form.

On Apr 6, 5:34 am, Ishbir  wrote:
> Thanks for your help, although I had to tweak the code to get it
> working. It finally works! Thank you.
>
> And by the way, do you know any way by which behaviours can be
> defined? For e.g. if a record is added, then do something, if record
> is deleted then do something. Can stuff like that be implemented in
> web2py?
>
> On Apr 5, 8:37 pm, Thadeus Burgess  wrote:
>
> > Your join is performing a union, your queries could (and will) get
> > quite huge, since your getting a record for every tag. (so for two
> > tags you actually get two rows for that snippet). A left join will
> > provide you with everything, but you still get a row for every tag.
>
> > Even with a left join you will still have to query for the title of the tag
>
> > >>> rows = db().select(db.snippets.ALL, db.snippet_tags_link.ALL, 
> > >>> left=db.snippet_tags_link.on(db.snippets.id == 
> > >>> db.snippet_tags_link.snippet_id))
> > >>> print rows
>
> > snippets.id,snippets.title,snippets.content,snippets.created,snippet_tags_link.id,snippet_tags_link.snippet_id,snippet_tags_link.tag_id
> > 1,hi,hello world,2010-04-05 09:21:20,1,1,1
> > 1,hi,hello world,2010-04-05 09:21:20,2,1,1
> > 2,woot,erifica,2010-04-05 09:21:20,,,
>
> > Or you can do a secondary query to get the tags.
>
> > snippets = db().select()
> > for snip in snippets:
> >    print snippet.title
> >    for tag in snip.snippet_tags_link.select():
> >       print tag.snippet_tags.name
>
> > -Thadeus
>
> > On Mon, Apr 5, 2010 at 8:46 AM, Ishbir  wrote:
> > > I've got some problem with the MANY-MANY relation in Web2Py. This is
> > > my code-
>
> > >http://pastie.textmate.org/903738
>
> > > Now, the problem is that the query returns only those records which
> > > have tags, not the ones without them. However, if I specify query|
> > > db.snippets.id>0 or anything, it gives me garbled results with all the
> > > tables mixed up and nothing right..
>
> > > Is there any way around this? I thought about using the tagging plugin
> > > but the issue is that I don't think it would be very efficient since I
> > > need to also display the tags on the index page and that would result
> > > in n+1 queries where n is the no. of snippets. Or I am just getting
> > > apprehensive and it will just take 2-3 queries to get the tags of
> > > snippet?
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "web2py-users" group.
> > > To post to this group, send email to web...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > web2py+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-06 Thread Ishbir
Thanks for your help, although I had to tweak the code to get it
working. It finally works! Thank you.

And by the way, do you know any way by which behaviours can be
defined? For e.g. if a record is added, then do something, if record
is deleted then do something. Can stuff like that be implemented in
web2py?

On Apr 5, 8:37 pm, Thadeus Burgess  wrote:
> Your join is performing a union, your queries could (and will) get
> quite huge, since your getting a record for every tag. (so for two
> tags you actually get two rows for that snippet). A left join will
> provide you with everything, but you still get a row for every tag.
>
> Even with a left join you will still have to query for the title of the tag
>
> >>> rows = db().select(db.snippets.ALL, db.snippet_tags_link.ALL, 
> >>> left=db.snippet_tags_link.on(db.snippets.id == 
> >>> db.snippet_tags_link.snippet_id))
> >>> print rows
>
> snippets.id,snippets.title,snippets.content,snippets.created,snippet_tags_link.id,snippet_tags_link.snippet_id,snippet_tags_link.tag_id
> 1,hi,hello world,2010-04-05 09:21:20,1,1,1
> 1,hi,hello world,2010-04-05 09:21:20,2,1,1
> 2,woot,erifica,2010-04-05 09:21:20,,,
>
> Or you can do a secondary query to get the tags.
>
> snippets = db().select()
> for snip in snippets:
>    print snippet.title
>    for tag in snip.snippet_tags_link.select():
>       print tag.snippet_tags.name
>
> -Thadeus
>
> On Mon, Apr 5, 2010 at 8:46 AM, Ishbir  wrote:
> > I've got some problem with the MANY-MANY relation in Web2Py. This is
> > my code-
>
> >http://pastie.textmate.org/903738
>
> > Now, the problem is that the query returns only those records which
> > have tags, not the ones without them. However, if I specify query|
> > db.snippets.id>0 or anything, it gives me garbled results with all the
> > tables mixed up and nothing right..
>
> > Is there any way around this? I thought about using the tagging plugin
> > but the issue is that I don't think it would be very efficient since I
> > need to also display the tags on the index page and that would result
> > in n+1 queries where n is the no. of snippets. Or I am just getting
> > apprehensive and it will just take 2-3 queries to get the tags of
> > snippet?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "web2py-users" group.
> > To post to this group, send email to web...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > web2py+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Problem with MANY-MANY relationship

2010-04-05 Thread Ishbir
Thinking of ditching MANY-MANY altogether, I have come up with this
approach which uses multiple=True-

http://web2py.pastebin.com/813ZELF5

However, the problem is that whenever I do something like
snippet.tags, it just gives me a string list with the IDs. How do I
make it give me a list of the tags associated with the record so that
I can access the name field with something like-

for tag in snippet.tags:
print tag.name

??

On Apr 5, 6:46 pm, Ishbir  wrote:
> I've got some problem with the MANY-MANY relation in Web2Py. This is
> my code-
>
> http://pastie.textmate.org/903738
>
> Now, the problem is that the query returns only those records which
> have tags, not the ones without them. However, if I specify query|
> db.snippets.id>0 or anything, it gives me garbled results with all the
> tables mixed up and nothing right..
>
> Is there any way around this? I thought about using the tagging plugin
> but the issue is that I don't think it would be very efficient since I
> need to also display the tags on the index page and that would result
> in n+1 queries where n is the no. of snippets. Or I am just getting
> apprehensive and it will just take 2-3 queries to get the tags of
> snippet?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.