4 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Map one property as ...
FromSent OnAttachments
sqAlembic29 Apr 2007 00:04 
Michael Bayer29 Apr 2007 07:43 
Eric Ongerth29 Apr 2007 10:09 
Michael Bayer29 Apr 2007 10:58 
Subject:[sqlalchemy] Re: Map one property as a function of two others? (one via a secondary table)
From:Michael Bayer (mike@zzzcomputing.com)
Date:04/29/2007 07:43:46 AM
List:com.googlegroups.sqlalchemy

On Apr 29, 2007, at 3:04 AM, sqAlembic wrote:

Again, I want to make physical_size respond as a property of Widget. I want to be able to initialize a new Widget instance, give it only a nominal_size, associate it with a WidgetModel, and thereby it acquires a physical_size. I'd like to be able to do the following:

wm1 = WidgetModel(mfr='FrobozzCo', name='GasketronXL') ws1 = WidgetSize(wm1, 10, 300) w1 = Widget(nominal_size=10) print '%s %s size %d measures: %d millimeters.' %

(w1.model.mfr, w1.model.name, w1.nominal_size, w1.physical_size)

FrobozzCo GasketronXL size 10 measures: 300 millimeters.

My attempts at the proper mapper to do this have, so far, resulted in error messages asking me to specify primary (and perhaps secondary) joins. Should I be joining widget_size_table to widget_model_table and then mapping to that join?

a relation like this cant be persisted so youd have to put the viewonly=True flag on it. see the docs on the viewonly flag, as well as the "handling large collections" section for some other strategies on properties that load special things.

Secondary question, regarding session.save(): apparently if I save at least one of my newly instantiated Widgets then my test code will show both as a result of the test query at the end; if I don't save either then neither one will result at the end. Why does saving only one of the instances result in both printing out at the end? Is it because of the widget<>model relation with backref?

relationships have "save-update" cascade as the default setting. you can turn off all cascade rules via "cascade=None". see the docs on "cascade rules".