hi gaetan,
thanks for your review.
On Fri, Sep 5, 2008 at 2:32 PM, Gaetan de Menten <[EMAIL PROTECTED]> wrote:
>
> On Mon, Sep 1, 2008 at 2:50 PM, alex bodnaru <[EMAIL PROTECTED]> wrote:
>
>> i've done a couple of extensions i found useful, and since their
>> simplicity i'm sure they might also serve as examples.
>>
>> all my scarce extensions knowledge comes from analyze of elixir and
>> existing extensions, and these help with simplifying my code (without
>> giving up functionality) and avoid patching elixir in order to achieve
>> some pervert solutions.
>>
>> please enjoy my work as, we all enjoy the work of others, especially
>> in the freeware world.
>>
>> 1. inverse_orphans:
>>
>> in persons.py you have
>> class Person(Entity):
>> id = Field(Integer, pk=True)
>> name = Field(Unicode(20))
>>
>> in books.py you have
>> from person import *
>> class Book(Entity):
>> id = Field(Integer, pk=True)
>> name = Field(Unicode(50))
>> author = ManyToOne('Person', inverse='books_authored')
>>
>> inverse_orphans()
>>
>> since a Person is a quite generic entity, you can't be sure he should
>> author books or cut throats or both, but in a suitable application, i
>> might ask for the books a person has authored etc. hence, will
>> silently add Person a books_authored OneToMany fully functional
>> relationship.
>
> IMO, your use case would be better done by using backrefs explicitly:
>
> class Person(Entity):
> id = Field(Integer, pk=True)
> name = Field(Unicode(20))
>
> in books.py you have
> from person import *
> class Book(Entity):
> id = Field(Integer, pk=True)
> name = Field(Unicode(50))
> author = ManyToOne('Person', backref='books_authored')
>
it did work with backref too, but the books_authored relationship won't show
in the person objects _descriptor.relationships, hence introspection would lack.
>
>> 2. record_owned
>> is an extension made after acts_as_versioned, just that it will add
>> the facility of auto recording the person that inserted and updated
>> each record in an Entity.
>>
>> there is also some advance over the versioned extension, in that you
>> may also fill manually defined fields, to allow them be part of a
>> relationship and/or have additional information.
>>
>> i will also patch the versioned extension to allow this customization,
>> keeping the present functionality as default.
>
> I only realize it now, but what you've done could be achieved much
> more simply, by using the "default" and "onupdate" keyword arguments
> to fields:
>
> def get_current_user(param=None):
> return current_user
>
> class Movie(Entity):
> title = Field(Unicode(30))
> year = Field(Integer)
> record_inserter = Field(Unicode(30), default=get_current_user)
> record_updater = Field(Unicode(30), onupdate=get_current_user)
>
agree with you, but i wanted to be able to pass an argument to the
callable get_current_user, and, of course, to be able to define that
on one line, with site-wide default.
i have followed your advices in your other mail and attached the
patched version there too.
> --
> 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
-~----------~----~----~----~------~----~------~--~---