Aha, I should have realized it was just the default cascade=save-
update.

Thanks for the response; I went and read some more as recommended.

So one strategy would be to just define physical_size as a method
inside of my Widget class, which goes and loads the physical_size of a
Widget instance from a widget_size_table.  Was I correct in thinking
the strategy I mentioned already (mapping the property to a join)
should work?  I would rather have the property mapped in, not
expressed as a class method, just so the syntax doesn't look different
for this property than for the other Widget properties.

> a relation like this cant be persisted

Does that mean that I could not, for example, assign a physical_size
to a bunch of Widgets and expect the system to figure out what updates
should therefore be made in the widget_size_table?  If so, that's OK
since that's the exact opposite of the information flow I'm looking
for.  I suppose setting viewonly=True can be seen as a way of
informing SQLAlchemy of exactly that fact so that it doesn't have to
try and figure out the reverse.

Thanks again!


On Apr 29, 7:44 am, Michael Bayer <[EMAIL PROTECTED]> wrote:
> 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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to