Controlling Schemifier naming conventions with MapperRules

I was recently asked how to stop Lift’s Mapper from flattening the naming of columns during its “schemification” process. Well, there is a little known configuration object in the net.liftweb.mapper package called MapperRules.

MapperRules contains a whole bunch of stuff that you can use to control the way that Mapper names stuff that it creates and how it will try and inspect your database. If you prefer (like me) to have columns and tables like first_name rather than firstname, then add the following to Boot.scala:

class Boot {
  def boot {
    ...
    MapperRules.tableName =  (_,name) => StringHelpers.snakify(name)
    MapperRules.columnName = (_,name) => StringHelpers.snakify(name)
    ...  
  } 
}

Thats it!

comments powered by Disqus