On Jan 25, 2007, at 9:35 AM, Christopher Arndt wrote:
> As you can see 'parent_id' is a self-referencing FK to the
> bookmarks table. The
> idea now is to allow users to have their own copies of mapped
> 'Bookmark'
> objects, that are a sort of child of an existing 'Bookmark' object
> and allow
> them to overwrite certain columns like e.g. 'title' and
> 'description'. But if
> the column is NULL, it should be looked up in the parent object/
> row. Sort-of
> like in class/object attributes in Python classes.
i almost understand what you mean, but what column is NULL? if the
"parent_id" column is null, then youre the topmost parent bookmark
(i.e. no parent to be looked up). if the "owner_id" column is null,
no user points to this bookmark.
it sounds like basically many users would point to a common record in
the "bookmark" table, and for those users who want to override
certain attributes, a new copy of that bookmark object is made for
them and a new record with their owner_id gets inserted into the
database. is that it ?
oh....you mean, yes, they have their local "bookmark" copy, but if an
attribute is NULL, it goes up to the parent. right:
class Bookmark(object):
def _get_inherited_attr(self, key):
if getattr(self, "_" + key) is None:
if self.parent is not None:
return getattr(self.parent, "_" + key)
return None
title = property(lambda self:self._get_inherited_attr("title"),
lambda self, value:self._title=value)
description = property(lambda self:self._get_inherited_attr
("description"), lambda self, value:self._description=value)
url = property(lambda self:self._get_inherited_attr("url"),
lambda self, value:self._url=value)
mapper(Bookmark, bookmark_table, properties={
'parent':relation(Bookmark, remote_side=bookmark_table.c.id),
'_title':bookmark_table.c.title,
'_description':bookmark_table.c.description,
'_url':bookmark_table.c.url
})
the above can be made more concise by creating your own property
class, i.e. a class that has __get__() and __set__() methods, instead
of using the "property()" function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---