you can use __init__ normally, if thats the question....the mapper decorates __init__ with its own to handle its internal accounting (which it illustrates in http://www.sqlalchemy.org/docs/adv_datamapping.myt#adv_datamapping_class ).


On Mar 17, 2006, at 4:45 PM, Qvx 3000 wrote:

> Is there a way to somehow move my create_campaign() function inside
> Campaign.__init__? It is not wery important, more the matter of style.
>

sure you can just say:

class Campaign(object):
        def __init__(self):
                self.id = Campaign.c.id.default.scalar()

looks pretty stylish to me... :)

Yes I like that part. I started using it a few posts of yours ago.

I was actually thinking on calling this function from within __init__:

def create_campaign(**kw):
    sql = "BEGIN :id := cc_util.create_campaign(...); END;"
    # ... execute procedure via cursor.execute (), and fetch result ID back
    return campaign_id # used to LOAD the object

and then to somehow fix the object in regard with objectstore/identitymap because you mention in the docs that __init__ is used to keep track of new objects (this is actually loaded from the database).

If not, I will make it as a @staticmethod called new or create.


Reply via email to