This is a little fidgety, so bear with me.

So I define some elixir models with properties on them.  This is
supposed to create InstrumentedAttributes as class methods, which I
can then use in queries like Movie.query.filter(Movie.title != None).
However, those attributes don't exist until after I explicitly run
setup_all(), which appears to be deprecated anyway.  Observe:

>>> from elixir import *
>>> metadata.bind = "sqlite:///console.db"
>>> metadata.bind.echo = True
>>> class Movie(Entity):
...   title = Field(Unicode)
...
>>> Movie.title
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Movie' has no attribute 'title'
>>> setup_all()
/Users/nick/bin/env/pylons-0.9.7/lib/python2.6/site-packages/
Elixir-0.6.1-py2.6.egg/elixir/entity.py:412: SADeprecationWarning:
Session.mapper is deprecated.  Please see
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper
for information on how to replicate its behavior.
>>> Movie.title
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x1868ef0>


Now, the problem.  I need that instrumented attribute if I'm going to
write a filter for a relationship.  Observe:


>>> from elixir import *
>>> class Belonger(Entity):
...   stuff = Field(Unicode)
...   haver = ManyToOne('Haver')
...
>>> class Haver(Entity):
...   all_belongings = OneToMany('Belonger')
...   some_belongings = OneToMany('Belonger', filter='Belonger.stuff !
= None')
...
>>> setup_all()
/Users/nick/bin/env/pylons-0.9.7/lib/python2.6/site-packages/
Elixir-0.6.1-py2.6.egg/elixir/entity.py:412: SADeprecationWarning:
Session.mapper is deprecated.  Please see
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper
for information on how to replicate its behavior.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.3-i386/egg/elixir/__init__.py", line
145, in setup_all
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 816,
in setup_entities
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 421,
in setup_properties
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 433,
in call_builders
  File "build/bdist.macosx-10.3-i386/egg/elixir/relationships.py",
line 414, in create_properties
  File "build/bdist.macosx-10.3-i386/egg/elixir/relationships.py",
line 722, in get_prop_kwargs
TypeError: 'str' object is not callable


Ok, so I can't use the string trick to define my filter expression.
And I can't refer to the InstrumentedAttribute before I call
setup_all.  What am I supposed to do, call setup_all between every
model definition?  Unfortunatly, I can't do that either, since the
reverse association then causes a KeyError since the class it's
related to isn't created yet.  Observe:

from elixir import *
class Belonger(Entity):
  stuff = Field(Unicode)
  havers = ManyToOne('Haver')

setup_all() # line 6

class Haver(Entity):
  all_belongers = OneToMany('Belonger')
  some_belongers = OneToMany('Belonger', filter=Belonger.stuff !=
None)

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    setup_all()
  File "build/bdist.macosx-10.3-i386/egg/elixir/__init__.py", line
145, in setup_all
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 816,
in setup_entities
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 193,
in setup_relkeys
  File "build/bdist.macosx-10.3-i386/egg/elixir/entity.py", line 433,
in call_builders
  File "build/bdist.macosx-10.3-i386/egg/elixir/relationships.py",
line 402, in create_non_pk_cols
  File "build/bdist.macosx-10.3-i386/egg/elixir/relationships.py",
line 569, in create_keys
  File "build/bdist.macosx-10.3-i386/egg/elixir/relationships.py",
line 452, in target
  File "build/bdist.macosx-10.3-i386/egg/elixir/__init__.py", line
106, in resolve
KeyError: 'Haver'

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to