On Monday, October 10, 2016 at 11:46:01 AM UTC-4, Luis Valladares wrote:
>
> It appear that i've sorted this out in the last crazy test, my problem 
> where in filter fields, this was my code before:
>
>  accion = 
> self.dbNueva.estatus_contratacion.validate_and_insert(**self.dbNueva.estatus_contratacion._filter_fields(x)).as_dict()
>
> Where x is a dict with all the fields i want to insert (including the id 
> of the field), but when i insert this, the id is ignored an its assigned 
> the next autoincrement id, i changed the code for this:
>
> accion = self.dbNueva.estatus_contratacion.validate_and_insert(id=x["id"], 
> **self.dbNueva.estatus_contratacion._filter_fields(x)).as_dict()
>
> And it work perfectly. i dont know if this is a bug or this is the way it 
> should work, but ._filter_fields appears to filter also the ID of the dict.
>

That is the intended behavior -- typically when you take an existing record 
and want to use it as the basis of a new insert, you do not want to insert 
the id, as the database handles the id creation.

Anyway, note that if x contains only fields that are in the table, there is 
no need to use ._filter_fields() at all (it's purpose is to filter out the 
id field as well as any fields that don't belong in the table). Just do 
.validate_and_insert(**x) (or **x.as_dict() if x is a Row object).

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to