I had seen that thread, but it doesn't make sense to add all that code to all of my mapper models when they're ordinary mappers with ordinary auto-increment primary keys, which I happen to be importing from the database used by the previous, PHP version of this app. The foreign keys have to match up properly. Meanwhile I changed it so that it keeps a Map in memory from old ids to mapper instances, and linked children to the mapper with the new id. But wouldn't the logic of saved_? make more sense the way I proposed?
------------------------------------- Peter Robinett<[email protected]> wrote: You need to set the mapper id field as editable. Here is what I had to do to use a MappedStringIndex as a primary key that I can set manually: /* MAC address as primary key */ def primaryKeyField = mac object mac extends MappedStringIndex(this, 17) with IndexedField [String] { override def dbDisplay_? = true override lazy val defaultValue = randomString(maxLen) /* allow user-defined primary key */ override def writePermission_? = true override def dbAutogenerated_? = false private var myDirty = false override def dirty_? = myDirty override def dirty_?(b : Boolean) = { myDirty = b; super.dirty_?(b) } override def fieldCreatorString(dbType: DriverType, colName: String): String = colName+" CHAR("+maxLen+") NOT NULL " } Peter On Aug 24, 5:30 pm, Naftoli Gugenheim <[email protected]> wrote: > I'm trying to import data from a non-mapper-based database to one that is. > I'm reading data with DB.exec and trying to save it using Mapper, but it's > not getting saved. I'm guessing that since I'm setting the id (in runSafe) it > thinks it needs to do an update, not an insert. Is there a workaround? Also, > doesn't this scenario break the logic of MetaMapper.saved_?() ? Wouldn't it > make more sense to have a saved flag that is cleared by default and set when > it's created as a result of a find, and after it's saved? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" 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/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
