On Dec 9, 2009, at 3:16 PM, Alessandro Dentella wrote:

> Hi,
> 
>  docs suggests (Mapping a Class against Multiple Tables) to build a mapper
>  as this:
> 
>      class AddressUser(object): pass
>      j = join(users_table, addresses_table)
>      mapper(AddressUser, j, properties={
>         'user_id': [users_table.c.user_id, addresses_table.c.user_id]
>      })
> 
>  as a way to "keep both of those columns set at the same value". That works
>  perfectly when I want to use one mapper to present the join and to add
>  new instances for both tables.
> 
>  As far as I can test it fails if I want to add a joined record composed of
>  one existent record and another that doesn't ye exists::
> 
>    new = AddressUser()
>    new.name = 'myself'
>    new.address = 'mys...@example.com' 
> 
>  It correctly creates a User instance and an Address instance.
>  But now I can't see how to add a record where the User is the already
>  existent user 'myself' and the address is a new one. Even if the user.id
>  is an already existent one SA will try to create a new obj (and in my real
>  case it complains about not present not nullable fields, clearly).
> 
>  Is it possible to create a mapper that does that too? In the particular
>  context I have I'd really would prefere not to split the operation in two
>  steps (User / address). 

yeah theres not any obvious way I'm seeing for it to do that.  the mapper is 
either going to create or update a single instance.    If it were me I'd just 
use relation() to make the link between the two tables, and then put accessors 
on the parent that pull from the child to make it look like "one" object.




> 
>  Any hints?
> 
>  thanks in advance
>  sandro    
>  *:-)
> 
> 
> 
> -- 
> Sandro Dentella  *:-)
> http://sqlkit.argolinux.org        SQLkit home page - PyGTK/python/sqlalchemy
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to