On Jul 18, 2006, at 11:18 PM, Daniel Miller wrote: > Take a look at this example in the Hibernate documentation: > > http://www.hibernate.org/hib_docs/v3/reference/en/html/example- > parentchild.html#example-parentchild-bidir > > Hibernate does not automatically add child to parent.children when > child.parent is set. Here is the code snippet from the example that > illustrates that (warning: this is Java code): > > Parent p = (Parent) session.load(Parent.class, pid); > Child c = new Child(); > c.setParent(p); > p.getChildren().add(c); > session.save(c); > session.flush(); > > Notice how it's necessary to do both c.parent = p and > p.children.append(c). They later combine these into a single > statement by adding an addChild() method to the parent object, but > that's totally outside of Hibernate. The key here is that the child > is managing the association since they set inverse=True on the > parent.children mapping. The p.children.append(c) is only there to > keep the p.children collection up-to-date in memory; it does not > cause any SQL to be executed. In my case that collection does not > need to be kept up-to-date so that step can be omitted. It may be > useful to add an inverse=True keyword arg to SA's relation() > function, which would tell SA not to update the relationship based > on items added to or deleted from that side of the association. > That would be closer to how Hibernate does it. >
right, but that implies that p.children is not a lazily-instrumented attribute, you can get the same thing in SA by saying "lazy=None". im not sure whats accomplished by having the backref not "update both sides"....why not just not specify the backref at all in that case ? this would be possible though, the backref does consist of not just the attribute bi-directional behavior, but also a hint used during a flush() that its a bi-directional relationship. > Wow, don't burn yourself out. I wasn't demanding that you implement > this feature, I just wanted to discuss it on the list. I even > started to work on a patch last night but it got too late and I had > to go to bed. Seriously, make sure you don't burn yourself out. > You've been an amazing source of help for everyone getting started > with SA, and it would be a shame if you couldn't keep working on it. sorry...im always burning myself out ! dont take it personal. tell you what, everyone on the SA list show up to new york city this weekend and ill buy everyone a beer. seriously. well maybe not 190 beers but something substantial...im glad to have everyone on board. even though i periodically lose it here (96 degree weather doesnt help....) ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users