[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Christopher Arndt

Karl Guertin schrieb:
 Looks like you want recursive single table inheritance [1].

It doesn't need to be recursive, just a two-level parent-child relation. And I
don't want to add any columns, so I was thinking that table inheritance is not
the right approach, but I'm not sure about that.

Chris

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Karl Guertin

On 1/25/07, Christopher Arndt [EMAIL PROTECTED] wrote:
 It doesn't need to be recursive, just a two-level parent-child relation. And I
 don't want to add any columns, so I was thinking that table inheritance is not
 the right approach, but I'm not sure about that.

I was thinking that you could check parent_id for null or not null and
map that way, but it doesn't look like  the polymorphic mapper can
handle that. Ah well.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Rick Morrison

You could do this in a single join using COALESCE on the fallback columns.

Rick

On 1/25/07, Karl Guertin [EMAIL PROTECTED] wrote:

 On 1/25/07, Christopher Arndt [EMAIL PROTECTED] wrote:
  It doesn't need to be recursive, just a two-level parent-child relation. 
  And I
  don't want to add any columns, so I was thinking that table inheritance is 
  not
  the right approach, but I'm not sure about that.

 I was thinking that you could check parent_id for null or not null and
 map that way, but it doesn't look like  the polymorphic mapper can
 handle that. Ah well.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Michael Bayer

COALESCEwow i need to read some SQL books again... :)

On Jan 25, 2007, at 11:17 AM, Rick Morrison wrote:


 You could do this in a single join using COALESCE on the fallback  
 columns.

 Rick

 On 1/25/07, Karl Guertin [EMAIL PROTECTED] wrote:

 On 1/25/07, Christopher Arndt [EMAIL PROTECTED] wrote:
 It doesn't need to be recursive, just a two-level parent-child  
 relation. And I
 don't want to add any columns, so I was thinking that table  
 inheritance is not
 the right approach, but I'm not sure about that.

 I was thinking that you could check parent_id for null or not null  
 and
 map that way, but it doesn't look like  the polymorphic mapper can
 handle that. Ah well.




 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Rick Morrison

Dude, you should be WRITING them!

On 1/25/07, Michael Bayer [EMAIL PROTECTED] wrote:

 COALESCEwow i need to read some SQL books again... :)

 On Jan 25, 2007, at 11:17 AM, Rick Morrison wrote:

 
  You could do this in a single join using COALESCE on the fallback
  columns.
 
  Rick
 
  On 1/25/07, Karl Guertin [EMAIL PROTECTED] wrote:
 
  On 1/25/07, Christopher Arndt [EMAIL PROTECTED] wrote:
  It doesn't need to be recursive, just a two-level parent-child
  relation. And I
  don't want to add any columns, so I was thinking that table
  inheritance is not
  the right approach, but I'm not sure about that.
 
  I was thinking that you could check parent_id for null or not null
  and
  map that way, but it doesn't look like  the polymorphic mapper can
  handle that. Ah well.
 
 
 
 
  


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: class-object-like attribute lookup

2007-01-25 Thread Michael Bayer


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 ?

ohyou 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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---