Steve Bergman wrote:
> So, is there a way to create a *new* object and feed it a dictionary in
> a concise way?  I can't just create an empty object and then use .set
> because, of course, it complains about missing attributes when I create
> the object.
I think you can do the same with the class method.

SO(**dict)
as it is the same as
SO(key1=a, key2=b)

>
> Also, the way I am doing things is to pass all function/method args  in
> **kw and setting allow_extra_fields and filter_extra_fields to True in
> the schema.  Any function arguments that don't go into the database just
> get a dummy line in the schema so they don't get stripped prematurely.
> Then, right before I actually add or update, I pop the extra values off
> to avoid the object complaining about unexpected attributes when I update.
>
> Does that sound like the most efficient way to do it?
>
If you have a schema that matches the database fields, you can :

d = dbSchema(allow_extra_fields=True,
filter_extra_fields=true).to_python(kw )
SO(**d) # if  you want to add
so.set(**d) # if you want to update

The schema to_python function would filter out fields it doesn't know.

Personally, I just scrape the database metaclass to create such a
schema so I don't even need to define one line by line and any changes
to the database table definition would be retrieved.

Reply via email to