On 2010-12-14, at 11:28 AM, Ramsey Gurley wrote: > Hi Jesse, > > On Dec 14, 2010, at 1:16 PM, Jesse Tayler wrote: > >> >> I'm implementing a method to populate new EOs with default values before >> save. >> >> I see lots of ERXEnterpriseObject methods beyond awakeFromInsertion, > > I would recommend init() instead of awakeFromInsertion. init() was added to > fix a bug where awakeFromInsertion gets called twice after a cascade delete > fails validation... or something (^_^)
I do this too. Here's an example for you from Bug.java in BugTracker (BTBusinessLogic) public void init(EOEditingContext ec) { super.init(ec); setPriority(Priority.MEDIUM); setState(State.ANALYZE); setTargetRelease(Release.clazz.defaultRelease(ec)); setIsRead(true); setIsFeatureRequest(false); setOriginator(People.clazz.currentUser(editingContext())); setOwner(People.clazz.currentUser(editingContext())); setDateSubmitted(new NSTimestamp()); setDateModified(new NSTimestamp()); Comment comment = (Comment) Comment.clazz.createAndInsertObject(ec); comment.setOriginator(originator()); comment.setBug(this); } > >> including nice looking things like DidInsertProcessor and so forth. >> >> I'd like to use the D2W rules to set values like "active" = "true" or >> "author" = "session.user" I don't believe that you want to use rules to set values. At least I've never seen that done. See the setOwner and setOriginator methods above for how BugTracker handles it in the model. David > > The d2wContext of your page is generally unavailable in your EO unless you > use thread locals. > > If you DO find yourself using thread locals in your model, I would suggest > you consider how you use them carefully so you don't end up with a model that > is totally dependent on one application. Ramsey is right, but if you start to use the EOEnterpriseObjectClazz you can move most of your implementation (accessor methods for current user, for example) into the model and out of the Session. You'll still need to set the values on sleep and wake in your application's Session class, but that should be easy to move from project to project. > >> Does anyone have some overview advice for those new to the more modern ER >> frameworks in terms of how to implement this common concept I'm after? > > ERXEntityClassDescription has some stuff for initializing values. So does > migrations. > > Ramsey > >> >> thanks for thoughts or insights -- >> > > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/webobjects-dev/programmingosx%40mac.com > > This email sent to programming...@mac.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com