On Tue, Jul 28, 2009 at 5:12 PM, fbettag <fr...@bett.ag> wrote:

>
> So far it looks like this:
>
>
> trait Stamped[OwnerType <: Stamped[OwnerType] with LongKeyedMapper
> [OwnerType] with IdPK] {
>        this: OwnerType =>
>
>        private val thisTyped = this.asInstanceOf[MapperType]
>
>         override def afterSave {
>                 createActionLog("create", this.getClass.toString, this.id)
>        }
>

There's no afterSave method on Mapper... that method is on MetaMapper.

You need to split your trait into two pieces... one that will be mixed into
the model instances and one that'll be mixed into the Meta model singleton
(or perhaps just one mixed into the Meta).

In terms of the afterSave (and other before and after stuff) method on
MetaMapper, that method returns a List of functions that take the instance
as a model that's being saved and does something.  I've changed the
signature to List[A => Unit] rather than List[A => Any] to avoid confusion
about the fact that the functions are not meant to return anything.

Does this help?


>
>        def afterUpdate {
>                createActionLog("update", this.getClass.toString, this.id)
>        }
>
>        def beforeDelete {
>                createActionLog("delete", this.getClass.toString, this.id)
>        }
>
>
>        private def createActionLog(action: String, klass: String, obj:
> Long)
> {
>                val log = new ActionLog
>                log.action(action).klass(klass).record(obj).save
>        }
>
> }
>
> Now i ensured that the OwnerType class has a LongKeyedMapper with
> IdPK.
>
> The final problem is:
>
> afterSave is supposed to return a List(Any) meaning List(OwnerType)..
> how can i find out what the OwnerType class is?
> And what is it supposed to return? Simply the unmodified record in my
> case?
>
> best regards
>
> On 27 Jul., 05:07, fbettag <fr...@bett.ag> wrote:
> > Hey guys,
> >
> > i#ve gotten this together, to get a log of who's editing what. The
> > trait will give you the idea:
> >
> > import java.util.Date
> > import model._
> > import net.liftweb.mapper._
> >
> > trait Stamped[OwnerType <: Stamped[OwnerType]] extends LongKeyedMapper
> > [OwnerType] with IdPK {
> >         this: OwnerType =>
> >
> >         private val thisTyped = this.asInstanceOf[MapperType]
> >
> >         def afterSave {
> >                 createActionLog("create", this.getClass.toString,
> this.id)
> >         }
> >
> >         def afterUpdate {
> >                 createActionLog("update", this.getClass.toString,
> this.id)
> >         }
> >
> >         def beforeDelete {
> >                 createActionLog("delete", this.getClass.toString,
> this.id)
> >         }
> >
> >         private def createActionLog(action: String, klass: String, obj:
> Long)
> > {
> >                 val log = new ActionLog
> >                 log.action(action).klass(klass).record(obj).save
> >         }
> >
> > }
> >
> > On every action i create a log. It's better than having only createdAt/
> > On which only idicates only the last change, but to have a history.
> >
> > My only problem is, the extends LongKeyedMapper is the only way to
> > make it compile with this.id as last parameter of createActionLog().
> >
> > The question is, how can i find out if the supplied OwnerType Model is
> > extended with LongKeyedMapper?
> >
> > Is it possible to supply some kinda subclass check on the supplied
> > OwnerType.
> >
> > Btw, i forgot what <: does (like in Stamped[OwnerType <: Stamped
> > [OwnerType]]).
> >
> > any help would be great!
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to