I want to create a custom method in a model to query in a polymorphic
association like below:
#table definitions:
db.define_table('contents')
db.define_table('attachments')
db.define_table('attached_to', Field('attachment', db.attachments),
Field('rel_id', 'integer'), Field('created_on', 'datetime'),
Field('rel_type', 'string'))

#a method in contents like:
def attachments():
self.attached_to.rel_id==self.contents.id) &
(self.attached_to.rel_type=="contents")

#usage:
db.contents(1).attachments

I've developed in other frameworks and I simply add a method in the
model to accomplish this task. Here I tried with VirtualFields but it
did'nt work and the book says "They can be used to simplify the user's
code without using additional storage but they cannot be used for
searching". What are the ways to do the same in this framework?

Reply via email to