Created
November 22, 2011 23:04
-
-
Save rktoomey/1387338 to your computer and use it in GitHub Desktop.
how to update using SalatDAO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| salat-core:master:0.0.8-SNAPSHOT> test:console | |
| [info] Formatting 2 Scala sources {file:/home/rose/workspace/salat/}salat-core(test)... | |
| [info] Compiling 2 Scala sources to /home/rose/workspace/salat/salat-core/target/scala-2.8.1.final/test-classes... | |
| [info] Starting scala interpreter... | |
| [info] | |
| Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> import com.novus.salat._ | |
| import com.novus.salat._ | |
| scala> import com.novus.salat.global._ | |
| import com.novus.salat.global._ | |
| scala> import com.mongodb.casbah.Imports._ | |
| import com.mongodb.casbah.Imports._ | |
| scala> import com.novus.salat.test.dao._ | |
| import com.novus.salat.test.dao._ | |
| scala> val theta1 = Theta(x = "x1", y = "y1") | |
| theta1: com.novus.salat.test.dao.Theta = Theta(4ecc2760e4b07a91ffc8782b,x1,y1) | |
| scala> val _id = ThetaDAO.insert(theta1) | |
| _id: Option[com.mongodb.casbah.Imports.ObjectId] = Some(4ecc2760e4b07a91ffc8782b) | |
| scala> val theRealId: ObjectId = _id.getOrElse(error("Oh no the sky has fallen")) | |
| theRealId: com.mongodb.casbah.Imports.ObjectId = 4ecc2760e4b07a91ffc8782b | |
| scala> val updated = theta1.copy(x = "x2") | |
| updated: com.novus.salat.test.dao.Theta = Theta(4ecc2760e4b07a91ffc8782b,x2,y1) | |
| scala> ThetaDAO.update(MongoDBObject("_id" -> theRealId), updated, false, false, new WriteConcern) | |
| scala> val updated_* = ThetaDAO.findOneByID(theRealId) | |
| updated_*: Option[com.novus.salat.test.dao.Theta] = Some(Theta(4ecc2760e4b07a91ffc8782b,x2,y1)) | |
| scala> updated_* == updated // WTF? Why aren't they equal? | |
| res1: Boolean = false | |
| scala> updated_*.getOrElse(error("ahhhh another option")) == updated // because it is an Option and it must be unwrapped! | |
| res3: Boolean = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment