Hello,
Thanks again for the quick reply!
I tried to isolate all the mapper columns to try to make it less
confusing, now I know that was not a good idea.
orm.mapper(User, user, properties={
'id': user.c.ID,
'_first_name': user.c.FirstName,
'_middle_name': user.c.MiddleName,
'_last_name': user.c.LastName,
'_salutation': user.c.Salutation,
'_username': user.c.Username,
'_password': user.c.Password,
'_personal_email': user.c.PersonalEmail,
'_bussiness_email': user.c.BussinessEmail,
'_birth_date': user.c.BirthDate,
'_profession': user.c.Profession,
'_contact': orm.composite(ContactInformation, user.c.HomePage,
user.c.Telephone, user.c.Fax,
user.c.Nextel),
'_home_address': orm.composite(
Address,
user.c.HomeAddress_Street,
user.c.HomeAddress_City,
user.c.HomeAddress_ZipCode
),
'_billing_address': orm.composite(
Address,
user.c.BillingAddress_Street,
user.c.BillingAddress_City,
user.c.BillingAddress_ZipCode
),
'active': user.c.Active
})
I made the Address class because in some places it makes it easy to
encapsulate this information. I don't have any relationship() as you
can see in the mapping, that's what I would want but within the
composite object. There is no address table in the schema as my
intention was to avoid a join (city in this case would have been lazy
loaded).
In order to get this behavior, do I must then create an address table
and join it through a "primaryjoin" in relationship()?
Thanks!
On Jan 10, 10:57 am, Michael Bayer <[email protected]> wrote:
> On Jan 10, 2011, at 1:10 PM, Arturo Sevilla wrote:
>
> > Hello,
>
> > I'm trying to do the following:
>
> > 'home': orm.composite(
> > Address,
> > user.c.HomeAddress_Street,
> > # The following column is a UUID but is a foreign key to a
> > mapped
> > # table in SQLAlchemy, ideally would be to say
> > relationship(City)
> > # and specify the column
> > user.c.HomeAddress_City,
> > user.c.HomeAddress_ZipCode
> > )
>
> I don't understand what this means, i think you're missing some context here
> that would make this easier for others to understand, are there *other*
> columns on "user" that also reference "city" ? I don't understand what
> "relationship() and specify the column" means. relationship() accepts a
> "primaryjoin" expression for this purpose, its in the docs. If you have
> "HomeAddress" and "WorkAddress", you'd make two relationships.
>
> I also have an intuition, since it seems like you want a variant on
> relationship(), that composite is definitely not what you want to be using,
> it pretty much never is, but a picture of all the relevant columns here would
> be helpful. You definitely cannot use a column that's part of a
> relationship() in a composite() as well and manipulating foreign keys through
> composites is not the intended usage.
>
>
>
> > As such I tried a simple if isinstance(city, uuid.UUID): city =
> > City.load(city), where this method is just:
> > @classmethod
> > def load(cls, id):
> > session = Session()
> > obj = session.query(cls).get(id)
> > session.close()
> > return obj
>
> > However during session.commit() it appears that my Session class (made
> > with scoped_session(sessionmaker()) ) goes to None (and crashes).
> > Is this an expected behavior?
>
> no, the scoped_session object always returns either an existing or a new
> Session and is never None.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.