Skip to content

Instantly share code, notes, and snippets.

@mariussoutier
Created January 18, 2011 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariussoutier/784253 to your computer and use it in GitHub Desktop.
Save mariussoutier/784253 to your computer and use it in GitHub Desktop.
// Best of both worlds - WebObjects + Scala
// valueForKeyPath operators
def parameters: NSArray[Parameter] = ...
def maxSortOrder = parameters.valueForKeyPath("sortOrder.@max").asInstanceOf[Int]
// Clone attributes of an EnterpriseObject (aka DB row with all non-relationship columns)
trait Cloning extends EOEnterpriseObject {
type EOType <: EOEnterpriseObject
def attributesWithoutNull = for (attributeKey <- attributeKeys toList; if valueForKey(attributeKey) != null) yield attributeKey
def cloneEO: EOType = {
val clone = ERXEOControlUtilities.createAndInsertObject(editingContext, entityName).asInstanceOf[EOType]
val thisSnapshot = snapshot
for (key <- attributesWithoutNull) clone.takeValueForKey(thisSnapshot.valueForKey(key), key)
clone
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment