Ming: Use a MappedClass but disable "auto-save" at model init

4 views
Skip to first unread message

Bastien Sevajol

unread,
Feb 10, 2017, 10:20:12 AM2/10/17
to TurboGears
Hello,

I'm comming from ming documentation:
To get help with using Ming, use the Ming Users mailing list or the TurboGears Users mailing list.
My first message has been rejected on Ming Users mailing list (reason: "Non-members are not allowed to post messages to this list"). So, according to Ming doc, i allow myself to post it here:

I'm starting to use Ming and i fail to modify MappedClass behaviour: I would like to instantiate my model classes without "auto add" them in the session.

I tried to decorate __ini__ method of my classes but without success (_InitDecorator always encapsulate my decoration). How can i change that ? I know i can make a session.expunge(my_new_instance) but i want the same behaviour for all model class instanciations.


Thank's
Bastien Sevajol.

Alessandro Molina

unread,
Feb 13, 2017, 2:02:50 PM2/13/17
to TurboGears
On Fri, Feb 10, 2017 at 4:20 PM, Bastien Sevajol <sevajol...@gmail.com> wrote:

I tried to decorate __ini__ method of my classes but without success (_InitDecorator always encapsulate my decoration). How can i change that ? I know i can make a session.expunge(my_new_instance) but i want the same behaviour for all model class instanciations.


The __init__ method is decorated by the metaclass, so the logic that adds it to the session is actually wrapping your init. That it so ensure any Ming specific behaviour happens after you already initialised the object.

Currently it is not meant to be possible to create an entity that the session is not aware of, but you might be able to achieve that by replacing __init__ **after** the class is declared (instead of overriding it inside the class declaration). 

Bastien Sevajol

unread,
Feb 22, 2017, 6:00:08 AM2/22/17
to turbo...@googlegroups.com

Hello,

Thank's for reply.


Currently it is not meant to be possible to create an entity that the session is not aware of, but you might be able to achieve that by replacing __init__ **after** the class is declared (instead of overriding it inside the class declaration). 

I will follow this way, thank's !

--
You received this message because you are subscribed to a topic in the Google Groups "TurboGears" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/turbogears/FpBFC69a2Vc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages