On Feb 22, 6:31 pm, weheh <[email protected]> wrote:
> I'm trying to create a hierarchical database object:
> db.define_table('object',
> SQLField('oid','integer',default=0), # id of
> parent object
> SQLField('name','string'),
> SQLField('description','text')
> )
>
> When I insert a new object via the db app interface, I want to be able
> to set the oid via a db lookup, like this:
>
> db.object.oid.requires=IS_IN_DB(db,'object.id','%(name)s')
That's a constraint (hint: constraints can be set / changed during
execution; since the execution environment for a request starts by
reading the model files, that's what sets up a particular context
default).
What is the lookup you would make?
When you have a parent create a child, you're already existing.
Are you talking about orphans trying to find a parent?
Well, if I'm object.name("c") and I want to find some parent
object.name("p") -- if that's where you want to start, then you would
do just what you say: look up (select) on that name, and if it
exists, then make the link.
Alternately, you could make your constraint and change the constraint
in the special case of creating a root object.
You just need to choose how you want to do it.
I'm not sure if this helped. If not, a little more about what you
want to accomplish might help.
Regards,
Yarko
>
> The problem with this approach is that it requires an entry. If this
> is the first entry, it won't work. And what if I don't want the object
> to be contained within another object?
>
> So really, I want to be able to do something like this, but I don't
> know the right way to do it. This obviously doesn't work:
>
> db.object.oid.requires=IS_IN_SET([Null,IS_IN_DB(db,'object.id','%(name)
> s')]
>
> So what IS the right way to do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---