[sqlalchemy] Suggestions for setup.py

2008-02-15 Thread Paul Johnston
Hi,

I've noticed that setuptools supports optional dependencies
http://peak.telecommunity.com/DevCenter/setuptools#declaring-extras-optional-features-with-their-own-dependencies

Would it be worth adding one of these for each database SA supports?

You could then do easy_install sqlalchemy mssql to get SA + the
appropriate dbapi.

Paul

--~--~-~--~~~---~--~~
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: integrity error not raised for null column

2008-02-15 Thread Michael Bayer


On Feb 15, 2008, at 11:14 AM, Michael Schlenker wrote:


 Michael Bayer schrieb:
 no idea.  below is a revised version, where the main revision is that
 theres no SQLAlchemy ;).  So I think you should submit this to the  
 bug
 tracker on www.sqlite.org.

 Actually this is sorta interesting since it would impact our own unit
 tests regarding sqlite as well (which is why we run them with mysql
 and postgres as part of our build as well).
 This is a known misfeature of sqlite..., its even documented in the  
 CREATE
 TABLE manpage for sqlite.


I wouldn't be so sure about that.  Not sure what you mean by  
manpage (since man sqlite3 just produces a single brief usage page),  
but the docs on the site at http://www.sqlite.org/ 
lang_createtable.html don't mention anything about NOT NULL failing;  
only that PRIMARY KEY does not imply NOT NULL, which is not all whats  
going on here.  This issue is specifically, NOT NULL will fail to  
issue an exception when used with a CREATE TABLE statement following a  
DROP of that same table, which had to have at least one row before it  
was dropped.  All of those conditions are needed to reproduce the bug  
(but note, the column in question is not a PRIMARY KEY column).   The  
bug is also not a failure of the constraint; sqlite3 does not allow  
the NULL value to go in and no row is inserted.  Its just that the  
error is not propagated the second time around.  So this is definitely  
just a bug, and may even be within pysqlite as opposed to sqlite itself.


--~--~-~--~~~---~--~~
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: integrity error not raised for null column

2008-02-15 Thread Jonathon Anderson

I'm trying to track down whose code is responsible for this problem.
Your example (and I suppose sqlalchemy) use an sqlite3 module, which
seems to only exist within the python source tree. upgrading pysqlite
from initd.org gives me a pysqlite2 module. (Using the
pysqlite2.dbapi2 module does not seem to carry the same error.)

So the bug seems present only in the python 2.5 sqlite3 module. What
next?

~jon

On Feb 15, 10:14 am, Michael Schlenker [EMAIL PROTECTED] wrote:
 Michael Bayer schrieb: no idea.  below is a revised version, where the main 
 revision is that  
  theres no SQLAlchemy ;).  So I think you should submit this to the bug  
  tracker onwww.sqlite.org.

  Actually this is sorta interesting since it would impact our own unit  
  tests regarding sqlite as well (which is why we run them with mysql  
  and postgres as part of our build as well).

 This is a known misfeature of sqlite..., its even documented in the CREATE
 TABLE manpage for sqlite.

 Michael

 --
 Michael Schlenker
 Software Engineer

 CONTACT Software GmbH           Tel.:   +49 (421) 20153-80
 Wiener Straße 1-3               Fax:    +49 (421) 20153-41
 28359 Bremenhttp://www.contact.de/         E-Mail: [EMAIL PROTECTED]

 Sitz der Gesellschaft: Bremen
 Geschäftsführer: Karl Heinz Zachries, Ralf Holtgrefe
 Eingetragen im Handelsregister des Amtsgerichts Bremen unter HRB 13215
--~--~-~--~~~---~--~~
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: integrity error not raised for null column

2008-02-15 Thread Jonathon Anderson

I think I understand the relationship between pysqlite2 and sqlite3
(the second being a stdlib snapshot of the first) and have found the
code in sqlalchemy that will use pysqlite2, if present, over sqlite3,
so having installed the latest version of pysqlite2, I should be fine.

Any idea why the library name changed? I think that's confusing me
more than anything.

I assume the stdlib sqlite module will be upgraded at Python 2.6?

~jon

On Feb 15, 2:03 pm, Jonathon Anderson [EMAIL PROTECTED] wrote:
 I'm trying to track down whose code is responsible for this problem.
 Your example (and I suppose sqlalchemy) use an sqlite3 module, which
 seems to only exist within the python source tree. upgrading pysqlite
 from initd.org gives me a pysqlite2 module. (Using the
 pysqlite2.dbapi2 module does not seem to carry the same error.)

 So the bug seems present only in the python 2.5 sqlite3 module. What
 next?

 ~jon

 On Feb 15, 10:14 am, Michael Schlenker [EMAIL PROTECTED] wrote:

  Michael Bayer schrieb: no idea.  below is a revised version, where the 
  main revision is that  
   theres no SQLAlchemy ;).  So I think you should submit this to the bug  
   tracker onwww.sqlite.org.

   Actually this is sorta interesting since it would impact our own unit  
   tests regarding sqlite as well (which is why we run them with mysql  
   and postgres as part of our build as well).

  This is a known misfeature of sqlite..., its even documented in the CREATE
  TABLE manpage for sqlite.

  Michael

  --
  Michael Schlenker
  Software Engineer

  CONTACT Software GmbH           Tel.:   +49 (421) 20153-80
  Wiener Straße 1-3               Fax:    +49 (421) 20153-41
  28359 Bremenhttp://www.contact.de/        E-Mail: [EMAIL PROTECTED]

  Sitz der Gesellschaft: Bremen
  Geschäftsführer: Karl Heinz Zachries, Ralf Holtgrefe
  Eingetragen im Handelsregister des Amtsgerichts Bremen unter HRB 13215
--~--~-~--~~~---~--~~
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: Suggestions for setup.py

2008-02-15 Thread Michael Bayer
h im not sure every DBAPI can get installed through easy_install  
tho.  pyscopg2 comes to mind.

On Feb 15, 2008, at 6:32 AM, Paul Johnston wrote:

 Hi,

 I've noticed that setuptools supports optional dependencies 
 http://peak.telecommunity.com/DevCenter/setuptools#declaring-extras-optional-features-with-their-own-dependencies

 Would it be worth adding one of these for each database SA supports?

 You could then do easy_install sqlalchemy mssql to get SA + the  
 appropriate dbapi.

 Paul

 


--~--~-~--~~~---~--~~
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: integrity error not raised for null column

2008-02-15 Thread Michael Bayer


On Feb 15, 2008, at 3:23 PM, Jonathon Anderson wrote:


 I think I understand the relationship between pysqlite2 and sqlite3
 (the second being a stdlib snapshot of the first) and have found the
 code in sqlalchemy that will use pysqlite2, if present, over sqlite3,
 so having installed the latest version of pysqlite2, I should be fine.

 Any idea why the library name changed? I think that's confusing me
 more than anything.


probably so you can have a separate pysqlite2 installed without  
conflicts over the built-in sqlite3.

 I assume the stdlib sqlite module will be upgraded at Python 2.6?

hopefully.  apparently theres unit tests in python 2.5 which are  
hardwired against an older version of sqlite (fail with newer versions).


--~--~-~--~~~---~--~~
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: update sequence on insert

2008-02-15 Thread Michael Bayer


On Feb 15, 2008, at 5:53 PM, Brett wrote:


 serial column instead. On sqlite the id column seems to always  
 generate
 a unique number.  I'm not sure what other databases do.  What's the  
 best
 way to address this? Here's an example of whats happening:

why not rely upon the sequence unconditionally ?  SA has arranged  
things such that if you never create your own PK values, the  
database's preferred methodology is used automatically (i.e. sqlite's  
or mysql's autoincrement, PG's SERIAL/sequence).



--~--~-~--~~~---~--~~
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] update sequence on insert

2008-02-15 Thread Brett


Hello all,

On a Postgres database when I explicitly insert a value into a column 
with a sequence on it the sequence doesn't get updated and can return 
ids that aren't unique.  This can be be fixed with SQLAlchemy equivalent of:
maxid = select max(id) on family;
select setval(family_id_seq, maxid+1)

...or with a default=some_func_that_returns_maxid_plus_one on the 
column.  The problem is this isn't fool proof since max(id) could change 
before the setval()/update in a multiuser/threaded environment.  Its 
more or less the same problem if I don't use the sequence and have a 
serial column instead. On sqlite the id column seems to always generate 
a unique number.  I'm not sure what other databases do.  What's the best 
way to address this? Here's an example of whats happening:

from sqlalchemy import *
#uri = 'sqlite:///:memory:' # this test works fine on sqlite
uri = 'postgres://server/test'
engine = create_engine(uri, echo=False)
metadata = MetaData(bind=engine)

family_table = Table('family', metadata,
  Column('id', Integer, Sequence('family_id_seq'),
 primary_key=True),
  Column('data', String(32)))
metadata.drop_all()
metadata.create_all()
family_table.insert(values={'id': 1}).execute(bind=engine)
family_table.insert(values={'id': 2}).execute(bind=engine)

# these two lines will fix the following error it but aren't guaranteed 
# to be safe
#maxid = engine.execute('select max(id) from family').fetchone()[0]
#engine.execute(select setval('family_id_seq', %s) % (maxid + 1))

# raises IntegrityError since id won't be unique
family_table.insert(values={'family': 'something'}).execute(bind=engine)

--~--~-~--~~~---~--~~
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: SQLAlchemy 0.4.3 Released

2008-02-15 Thread maxi

Great Job !!!

How can I upgrade from 0.4.2p3 ?  (Or I have to uninstall all previous
version?)

Regards.







--~--~-~--~~~---~--~~
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: SQLAlchemy 0.4.3 Released

2008-02-15 Thread shday

try:

easy_install --upgrade SQLAlchemy

No need to uninstall.

http://peak.telecommunity.com/DevCenter/EasyInstall#upgrading-a-package


On Feb 15, 7:39 pm, maxi [EMAIL PROTECTED] wrote:
 Great Job !!!

 How can I upgrade from 0.4.2p3 ?  (Or I have to uninstall all previous
 version?)

 Regards.
--~--~-~--~~~---~--~~
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: Has anyone implemented a dict of lists collection_class?

2008-02-15 Thread Eric Ongerth

In case I didn't make it clear enough -- I've already done the
following:

'children': relation(Bar,
collection_class=attribute_mapped_collection('foo'),
backref=backref('parent', remote_side=[bars.c.id])) } )

And that worked great -- if I only needed to have up to a SINGLE child
per bar per foo.  Because the dict in attribute_mapped_collection
expects scalar keys and scalar values, right?  It's not set up to
collect a whole list of values per key.  And that is what I need.  Any
given Foo is only going to appear once in the keys of any given Bar's
children DictOfLists, of course.  But the values mapped to that given
Foo need to be a list of Bars of any length.  Any given Bar will have
1..n children in the bars table; each of these child Bars will be
related to a single Foo, but the total number of Foos is  n, so a
parent Bar might have a number of child Bars for a given Foo, while
only having zero or one single child Bar for some other Foo.

There, I think that tells it more completely.  Sorry for the
metasyntactic variables.


On Feb 15, 8:13 pm, Eric Ongerth [EMAIL PROTECTED] wrote:
 If anyone out there has already implemented a custom DictOfLists
 collection class to map scalar keys to lists of values, I would be
 grateful for the opportunity to avoid reinventing the wheel.  If not,
 I guess I'll start working on it.

 I've experimented successfully with attribute_mapped_collection and
 column_mapped_collection and they work just great.  However, instead
 of mapping keys to single values, I need some of my mapper relations
 to map to a list of values.

 Here is more of the picture, for example.

 foos = Table('foos', metadata,
 Column('id', Integer, primary_key=True),
 Column('name', String(20)))

 bars = Table('bars', metadata,
 Column('id', Integer, primary_key=True),
 Column('foo_id', Integer, ForeignKey('foos.id')),
 Column('value', String(20)),
 Column('parent_id', Integer, ForeignKey('bars.id')))

 class Foo(object): pass
 class Bar(object): pass

 mapper(Foo, foos)

 mapper(Bar, bars, properties={
 'foo':relation(Foo, uselist=False, backref='bars'),
 'children':relation(Bar,
 backref=backref('parent',
 remote_side=[bars.c.id]))

 })

 ... So we have a relation of 1 Foo : many Bars.  And within the Bars
 we also have 'adjacency' (tree-like) relations between the various
 rows of the 'bars' table.  A Bar's children are kept in the standard
 list-like collection class.

 But what I really need is a *dict* instead of a list.  Ok, SA already
 takes care of that.  But I actually need a list-like collection to
 appear as the value for each key in the dict.  Specifically, I need
 each Bar to be able to have stored children *per Foo*.  And not keyed
 by the parent's foo, but the child's foo.

 Does that make sense?  I'll be working on this immediately, but if
 anyone can shorten my path to getting this straight I'd be very glad.
 I'm beginning to work out the use of a custom collection_class for
 this, but I haven't done all that much with metaclassing and the way
 forward isn't obvious (the SA instructions about this seem to assume
 the programmer is pretty experienced with custom subclassing etc.)
--~--~-~--~~~---~--~~
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] Has anyone implemented a dict of lists collection_class?

2008-02-15 Thread Eric Ongerth

If anyone out there has already implemented a custom DictOfLists
collection class to map scalar keys to lists of values, I would be
grateful for the opportunity to avoid reinventing the wheel.  If not,
I guess I'll start working on it.

I've experimented successfully with attribute_mapped_collection and
column_mapped_collection and they work just great.  However, instead
of mapping keys to single values, I need some of my mapper relations
to map to a list of values.

Here is more of the picture, for example.

foos = Table('foos', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(20)))

bars = Table('bars', metadata,
Column('id', Integer, primary_key=True),
Column('foo_id', Integer, ForeignKey('foos.id')),
Column('value', String(20)),
Column('parent_id', Integer, ForeignKey('bars.id')))

class Foo(object): pass
class Bar(object): pass

mapper(Foo, foos)

mapper(Bar, bars, properties={
'foo':relation(Foo, uselist=False, backref='bars'),
'children':relation(Bar,
backref=backref('parent',
remote_side=[bars.c.id]))
})


... So we have a relation of 1 Foo : many Bars.  And within the Bars
we also have 'adjacency' (tree-like) relations between the various
rows of the 'bars' table.  A Bar's children are kept in the standard
list-like collection class.

But what I really need is a *dict* instead of a list.  Ok, SA already
takes care of that.  But I actually need a list-like collection to
appear as the value for each key in the dict.  Specifically, I need
each Bar to be able to have stored children *per Foo*.  And not keyed
by the parent's foo, but the child's foo.

Does that make sense?  I'll be working on this immediately, but if
anyone can shorten my path to getting this straight I'd be very glad.
I'm beginning to work out the use of a custom collection_class for
this, but I haven't done all that much with metaclassing and the way
forward isn't obvious (the SA instructions about this seem to assume
the programmer is pretty experienced with custom subclassing etc.)
--~--~-~--~~~---~--~~
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: Has anyone implemented a dict of lists collection_class?

2008-02-15 Thread Eric Ongerth

Ok, I tried subclassing MappedCollection and it seems like I did all
right with my made-up appender, remover, and iterator functions.  At
least I fixed various errors and got this to at least function as the
collection_class for the mapper shown above.

But I can't figure out how to tell my DictOfLists to return a list
instead of a single item.  So there's a place where I'm trying to say:
for child in some_bar.children[some_foo]:
blah(child)
etc.

Sadly, while some_bar.children[some_foo] at least returns something,
it returns a scalar Bar instance, not a list of Bars as I want it too.

What's the next step?



On Feb 15, 8:21 pm, Eric Ongerth [EMAIL PROTECTED] wrote:
 In case I didn't make it clear enough -- I've already done the
 following:

 'children': relation(Bar,
 collection_class=attribute_mapped_collection('foo'),
 backref=backref('parent', remote_side=[bars.c.id])) } )

 And that worked great -- if I only needed to have up to a SINGLE child
 per bar per foo.  Because the dict in attribute_mapped_collection
 expects scalar keys and scalar values, right?  It's not set up to
 collect a whole list of values per key.  And that is what I need.  Any
 given Foo is only going to appear once in the keys of any given Bar's
 children DictOfLists, of course.  But the values mapped to that given
 Foo need to be a list of Bars of any length.  Any given Bar will have
 1..n children in the bars table; each of these child Bars will be
 related to a single Foo, but the total number of Foos is  n, so a
 parent Bar might have a number of child Bars for a given Foo, while
 only having zero or one single child Bar for some other Foo.

 There, I think that tells it more completely.  Sorry for the
 metasyntactic variables.

 On Feb 15, 8:13 pm, Eric Ongerth [EMAIL PROTECTED] wrote:

  If anyone out there has already implemented a custom DictOfLists
  collection class to map scalar keys to lists of values, I would be
  grateful for the opportunity to avoid reinventing the wheel.  If not,
  I guess I'll start working on it.

  I've experimented successfully with attribute_mapped_collection and
  column_mapped_collection and they work just great.  However, instead
  of mapping keys to single values, I need some of my mapper relations
  to map to a list of values.

  Here is more of the picture, for example.

  foos = Table('foos', metadata,
  Column('id', Integer, primary_key=True),
  Column('name', String(20)))

  bars = Table('bars', metadata,
  Column('id', Integer, primary_key=True),
  Column('foo_id', Integer, ForeignKey('foos.id')),
  Column('value', String(20)),
  Column('parent_id', Integer, ForeignKey('bars.id')))

  class Foo(object): pass
  class Bar(object): pass

  mapper(Foo, foos)

  mapper(Bar, bars, properties={
  'foo':relation(Foo, uselist=False, backref='bars'),
  'children':relation(Bar,
  backref=backref('parent',
  remote_side=[bars.c.id]))

  })

  ... So we have a relation of 1 Foo : many Bars.  And within the Bars
  we also have 'adjacency' (tree-like) relations between the various
  rows of the 'bars' table.  A Bar's children are kept in the standard
  list-like collection class.

  But what I really need is a *dict* instead of a list.  Ok, SA already
  takes care of that.  But I actually need a list-like collection to
  appear as the value for each key in the dict.  Specifically, I need
  each Bar to be able to have stored children *per Foo*.  And not keyed
  by the parent's foo, but the child's foo.

  Does that make sense?  I'll be working on this immediately, but if
  anyone can shorten my path to getting this straight I'd be very glad.
  I'm beginning to work out the use of a custom collection_class for
  this, but I haven't done all that much with metaclassing and the way
  forward isn't obvious (the SA instructions about this seem to assume
  the programmer is pretty experienced with custom subclassing etc.)
--~--~-~--~~~---~--~~
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: Has anyone implemented a dict of lists collection_class?

2008-02-15 Thread Eric Ongerth

Incidentally, I tried mocking this all up entirely outside of SA by
creating a DictOfLists class that subclasses the basic 'dict'.  That
worked fine, returns lists, adds and removes as desired, handles
everything as one would expect.  So I don't think I'm fumbling with
the basic mechanics of it.


On Feb 15, 11:41 pm, Eric Ongerth [EMAIL PROTECTED] wrote:
 Ok, I tried subclassing MappedCollection and it seems like I did all
 right with my made-up appender, remover, and iterator functions.  At
 least I fixed various errors and got this to at least function as the
 collection_class for the mapper shown above.

 But I can't figure out how to tell my DictOfLists to return a list
 instead of a single item.  So there's a place where I'm trying to say:
 for child in some_bar.children[some_foo]:
 blah(child)
 etc.

 Sadly, while some_bar.children[some_foo] at least returns something,
 it returns a scalar Bar instance, not a list of Bars as I want it too.

 What's the next step?

 On Feb 15, 8:21 pm, Eric Ongerth [EMAIL PROTECTED] wrote:

  In case I didn't make it clear enough -- I've already done the
  following:

  'children': relation(Bar,
  collection_class=attribute_mapped_collection('foo'),
  backref=backref('parent', remote_side=[bars.c.id])) } )

  And that worked great -- if I only needed to have up to a SINGLE child
  per bar per foo.  Because the dict in attribute_mapped_collection
  expects scalar keys and scalar values, right?  It's not set up to
  collect a whole list of values per key.  And that is what I need.  Any
  given Foo is only going to appear once in the keys of any given Bar's
  children DictOfLists, of course.  But the values mapped to that given
  Foo need to be a list of Bars of any length.  Any given Bar will have
  1..n children in the bars table; each of these child Bars will be
  related to a single Foo, but the total number of Foos is  n, so a
  parent Bar might have a number of child Bars for a given Foo, while
  only having zero or one single child Bar for some other Foo.

  There, I think that tells it more completely.  Sorry for the
  metasyntactic variables.

  On Feb 15, 8:13 pm, Eric Ongerth [EMAIL PROTECTED] wrote:

   If anyone out there has already implemented a custom DictOfLists
   collection class to map scalar keys to lists of values, I would be
   grateful for the opportunity to avoid reinventing the wheel.  If not,
   I guess I'll start working on it.

   I've experimented successfully with attribute_mapped_collection and
   column_mapped_collection and they work just great.  However, instead
   of mapping keys to single values, I need some of my mapper relations
   to map to a list of values.

   Here is more of the picture, for example.

   foos = Table('foos', metadata,
   Column('id', Integer, primary_key=True),
   Column('name', String(20)))

   bars = Table('bars', metadata,
   Column('id', Integer, primary_key=True),
   Column('foo_id', Integer, ForeignKey('foos.id')),
   Column('value', String(20)),
   Column('parent_id', Integer, ForeignKey('bars.id')))

   class Foo(object): pass
   class Bar(object): pass

   mapper(Foo, foos)

   mapper(Bar, bars, properties={
   'foo':relation(Foo, uselist=False, backref='bars'),
   'children':relation(Bar,
   backref=backref('parent',
   remote_side=[bars.c.id]))

   })

   ... So we have a relation of 1 Foo : many Bars.  And within the Bars
   we also have 'adjacency' (tree-like) relations between the various
   rows of the 'bars' table.  A Bar's children are kept in the standard
   list-like collection class.

   But what I really need is a *dict* instead of a list.  Ok, SA already
   takes care of that.  But I actually need a list-like collection to
   appear as the value for each key in the dict.  Specifically, I need
   each Bar to be able to have stored children *per Foo*.  And not keyed
   by the parent's foo, but the child's foo.

   Does that make sense?  I'll be working on this immediately, but if
   anyone can shorten my path to getting this straight I'd be very glad.
   I'm beginning to work out the use of a custom collection_class for
   this, but I haven't done all that much with metaclassing and the way
   forward isn't obvious (the SA instructions about this seem to assume
   the programmer is pretty experienced with custom subclassing etc.)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---