On Tue, Sep 15, 2009 at 12:35, Christopher Arndt <[email protected]> wrote:

> first post on the list.

Welcome in.

> I searched the answer in the docs and in the ml
> archives, but couldn't find it.
>
> I have a traditional SLQAlchemy mapped class like the following:
>
> user_table = Table(...)
>
> class User(object):
>    def _set_password(self, password):
>        """Run cleartext password through the hash algorithm before
> saving."""
>        self._password = encrypt_password(password)
>
>    def _get_password(self):
>        """Returns password."""
>        return self._password
>
>    # 'password' is a table column
>    password = property(_get_password, _set_password)
>
> mapper(User, user_table,
>     properties=dict(_password=user_table.c.password))
>
> How would I do that with an elixir.Entity base class? I only found how
> to define a method that mangles the value on read access, but how do I
> do this when setting a property?

Here is the way you'd do it in Elixir:

class User(Entity):
    def _set_password(self, password):
        """Run cleartext password through the hash algorithm before
 saving."""
        self._password = encrypt_password(password)

    def _get_password(self):
        """Returns password."""
        return self._password

    # 'password' is a table column
    password = property(_get_password, _set_password)

    _password = Field(String(20), colname='password')


-- 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to