One quick follow up. re: question 2: If I create a User there, and that user exists in the DB, won't that cause problems? I ask because this situation seems analogous to a "create if not existing" situation.
Thanks for the (as ever) fast response. GL On Fri, Aug 14, 2009 at 5:20 PM, Michael Bayer <[email protected]>wrote: > > Gregg Lind wrote: > > I have a many-to-one relation, let's say between Address and User, both > > created using Declarative. > > > > I would like it that if an Address references a User, it will create that > > User, if it doesn't exist. Otherwise, it should use the existing one. > > There should be no addresses in the table that don't have users. *It > > could > > be that my whole sense of modeling is fouled up here, and I appreciate > > correction.* > > > > 1. Is this possible using the current _cascade_ tools? Is so, how is it > > set up? > > no, since you're talking about instantiating an object that doesn't exist > otherwise. > > > 2. If not, then what is the best way to handle this? > > the constructor of your Address says, "self.user = User(<args you want>)". > If that's too early, you can write a SessionExtension.before_flush() > that scans through and ensures all Address objects have a default User() > as desired. > > > 3. From the docs for "relation" it seems like the cascading is all > viewed > > from the "parent" (one) side, is that correct? > > all relation()s feature cascading. A two-way relationship consists of > two separate relation()s, "backref" is just a shortcut to creating them > and linking them together. "parent" and "child" are relative to which > relation() you're referring to. > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
