2

Is there a way of creating method for setting the value in the Model's fields without setting the values explicitly like -

ModelName.create.fieldName1("value").fieldName2("value2") and so on

Can we iterate through all available fields of that model and set their values form some list-of-values ?

something like ...

Model.allFields.foreach((fld)=> {
fld.set(valueList(indx)); indx+=1
}

Actually I want to set values into all models using some generic method that works for all models.

vkantiya
  • 1,343
  • 1
  • 8
  • 20
  • Looking at http://scala-tools.org/mvnsites/liftweb-2.4-M5/#net.liftweb.record.Record and http://scala-tools.org/mvnsites/liftweb-2.4-M5/#net.liftweb.record.Field suggests that it is possible. Also scala List.zip function may helps you to avoid increase index – viktortnk Nov 22 '11 at 09:44

1 Answers1

0

According to my comment:

val list = List(...)
val record = YourRecordClass.createRecord
record.allFields.zip(list).foreach {case(field,value) => field.setFromAny(value)}
viktortnk
  • 2,739
  • 1
  • 19
  • 18