I suppose you could just make it type='integer'. Then you could use the IS_IN_SET validator and construct a list of id's from the two tables (keeping in mind you should de-dup the list, as both tables will have many of the same id's). Of course, if you end up storing a value of say, 5, you won't know if it is referencing record #5 in the melon table or record #5 in the watermelon table.
Anthony On Friday, May 23, 2014 5:24:49 PM UTC-4, Louis Amon wrote: > > Well in this particular case I needn't know wether I'm storing a melon or > a watermelon's id. > > I know it's kind of idiotic but I just need a 'fruit' id. > > Think of it as a subclassing matter : the API I'm connecting to is doing > something along the lines of subclassing anyway, and I need to store data > about every transaction my program does with this poorly-designed API > > Le 23 mai 2014 à 23:03, "Anthony" <abasta...@gmail.com> a écrit : > > How would you know whether the field stores an id of the melon table or > the watermelon table? > > On Friday, May 23, 2014 4:52:58 PM UTC-4, Louis Amon wrote: >> >> Due to external constraints, I need to define two tables that are >> actually siblings and a third table's field that can choose from any of >> said tables. >> >> e.g.: >> db.define_table('melon') >> db.define_table('watermelon') >> >> I need the third table's field to be a reference to either of the two >> first tables. >> >> Is there a way to define this in terms of field type and validators ? >> I was thinking along the lines of: >> >> db.define_table('my_table', Field('fruit_id', type=???, >> requires=IS_IN_DB(db, db.melon, _or=IS_IN_DB(db, db.watermelon))) >> >> or maybe: >> >> db.define_table('my_table', Field('fruit_id', type=???, >> requires=any([IS_IN_DB(db, db.melon), IS_IN_DB(db, db.watermelon)])) >> >> But of course it doesn't work... >> >> >> How can I work around this issue ? >> >> -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/nd6ED9oScsA/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.