Wrapping a field in a property works fine (See the attached file which
is your example debugged -- your way to define a property is quite...
peculiar).
See:
http://www.sqlalchemy.org/docs/adv_datamapping.html#advdatamapping_properties_overriding
for details how it's done in SQLAlchemy.
What doesn't work (yet) in Elixir is the synonym part. It means that
you can't have a property named the same way than the column it is
wrapping, and you'll have to use the column name in get_by, select_by
and so on... I'll add this to our TODO list, but don't hold your
breath ;-).
On 5/3/07, Nando Florestan <[EMAIL PROTECTED]> wrote:
>
> I am wrong. Forget all that.
>
> As soon as an instance of CatCateg is created, my property, my beloved
> property, is replaced by a sqlalchemy.orm.unitofwork.UOWProperty
> object.
>
> So back to my original question: What is an easy way of wrapping
> fields in my own properties?
>
>
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
from elixir import *
class CatCateg(Entity):
has_field("id", Integer, primary_key=True)
has_field("_name", Unicode(40), required=True)
# Notice it is called "name" in the DB, but "_name" in the class.
# The property!
def fget(self):
return self._name
def fset(self, val):
# For now we just check for empty string, but anything could
# happen
if val == "":
raise RuntimeError("You can't have an empty name.")
self._name = val
name = property(fget, fset)
metadata.connect('sqlite:///')
create_all()
x = CatCateg(name="test")
objectstore.flush()
objectstore.clear()
#test = CatCateg.get_by(name="test")
test = CatCateg.get_by(_name="test")
print test.id, test.name