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". --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---