Specific order for creating table columns with Mapper?

29 views
Skip to first unread message

Nice Placer

unread,
Jun 9, 2011, 4:03:30 PM6/9/11
to lif...@googlegroups.com
Hello folks :)

Short question about creating tables via mapper. I am doing this:

object Table1 extends Table1 with LongKeyedMetaMapper[Table1] {
  override def dbTableName = "Table1"
}
class Table1 extends LongKeyedMapper[Table1] with IdPK {
  def getSingleton = Table1
  object text1 extends MappedString(this,40);
  object text2 extends MappedString(this,40);
  object value extends MappedInt(this);
  object date extends MappedDate(this);
}

Mapper creates a table (MySql) and all works fine. Unfortunately id, which I have expected as first column is somewhere else and order is different as expected. With code above, I would have expected AND wanted an order like this:
id, text1, text2, value, date.
How can I achieve that?

Thx for reading and for answering in advance ;)

Artie Pesh-Imam

unread,
Jun 9, 2011, 4:14:56 PM6/9/11
to lif...@googlegroups.com
Here's a code snippet on how to accomplish this: 

object Expense extends Expense with LongKeyedMetaMapper[Expense] {
  override def fieldOrder = List(dateOf, description, amount)
}


Just search for fieldOrder.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/l2fusOGXNS8J.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Artie Peshimam

unread,
Jun 9, 2011, 4:18:50 PM6/9/11
to lif...@googlegroups.com
Apologies that was incorrect. This controls the display of the rendering of the fields.

Nice Placer

unread,
Jun 9, 2011, 6:30:34 PM6/9/11
to lif...@googlegroups.com
Hey Artie,
thx. I think, you are not wrong. This probably will work for both.

I am one step further. Code is now:


object Table1 extends Table1 with LongKeyedMetaMapper[Table1] {
  override def dbTableName = "Table1"
  override def fieldOrder = List(id,text1,text2,value,date)
}
class Table1 extends LongKeyedMapper[Table1] with IdPK {
  def getSingleton = Table1
  def primaryKeyField = id

object id extends MappedLongIndex(this)
  object text1 extends MappedString(this,40);
  object text2 extends MappedString(this,40);
  object value extends MappedInt(this);
  object date extends MappedDate(this);
}

Now I get a compiler error, a type mismatch:

found   : Table1.this.id.type (with underlying type object Table1.this.id)
required: object Table1.this.id
   def primaryKeyField = id;

Argh ..... :-S Anybody can help?

Thank you in advance.

David Pollak

unread,
Jun 9, 2011, 6:34:40 PM6/9/11
to lif...@googlegroups.com


Remove:

  def primaryKeyField = id

object id extends MappedLongIndex(this)

That's what the IdPK trait gives you.
 

Thank you in advance.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/SX9YRYRh-r8J.

To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net

Nice Placer

unread,
Jun 9, 2011, 6:57:52 PM6/9/11
to lif...@googlegroups.com
Thx David.

Now it works. I thought, I would not be able to use id in fieldorder... ;)


Reply all
Reply to author
Forward
0 new messages