It's not pretty, but:

trait MyLogger[A <: KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] {
   self: A  with MetaMapper[A] with KeyedMapper[K, A] =>

  override def afterSave = doSomething _ :: super.afterSave

  private def doSomething(in: A) {
    println("Got "+in)
  }
}


On Wed, Jul 29, 2009 at 3:35 PM, fbettag <fr...@bett.ag> wrote:

>
> Hm. i changed it to this:
> trait Stamped[OwnerType <: Mapper[OwnerType] with IdPK] {
>        self: MetaMapper[OwnerType] =>
>
>        private val thisTyped = this.asInstanceOf[MapperType]
>
>         override def afterSave: List[Any] = {
>                createActionLog("create", this.getClass.toString,
> thisTyped.id)
>                return List(None)
>        }
>
>        def afterUpdate: List[Any] = {
>                createActionLog("update", this.getClass.toString,
> thisTyped.id)
>                return List(None)
>        }
>
>        def beforeDelete: List[Any] = {
>                createActionLog("delete", this.getClass.toString,
> thisTyped.id)
>                return List(None)
>         }
>
>
>        private def createActionLog(action: String, klass: String, obj:
> Long)
> {
>                val log = new ActionLog
>                log.action(action).klass(klass).record(obj).save
>        }
>
> }
>
> and i extend the object now and not the class. still i get these:
>
> src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method
> afterSave overrides nothing
>        override def afterSave: List[Any] = {
>                     ^
> method afterSave in trait Stamped of type => List[Any] needs
> `override' modifier
> object Content extends Content with LongKeyedMetaMapper[Content] with
> Stamped[Content] {
>       ^
>
>
> This is voodoo again :(
>
> On 29 Jul., 22:55, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> > trait Foo[A <: Mapper[A]] {
> >   self: MetaMapper[A] =>
> >
> >
> >
> > }
> > On Wed, Jul 29, 2009 at 1:38 PM, fbettag <fr...@bett.ag> wrote:
> >
> > > Yes thanks, it gives me an idea of the issue which i now see.
> > > Could you provide a very simple example on how you would make the Meta-
> > > Mixin?
> > > That would be very good
> >
> > > best regards
> >
> > > On 29 Jul., 21:55, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> > > > 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?
> >
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Git some:http://github.com/dpp
> >
>


-- 
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