Skip to content

Add updatedAt and createdAt traits to Record #1347

Open
eltimn opened this Issue Nov 3, 2012 · 6 comments

4 participants

@eltimn
Lift Web Framework member
eltimn commented Nov 3, 2012

No description provided.

@eltimn eltimn was assigned Nov 3, 2012
@nafg
nafg commented Nov 4, 2012

Is the idea to make a trait to mix into the record, or to mix into the field? I hope the latter --- it's allows for more flexibility.

@eltimn
Lift Web Framework member
eltimn commented Nov 4, 2012

The idea was to create traits to mix into a record, the same way the Mapper traits work. I'm not sure what traits meant to be mixed into a Field would look like. What did you have in mind?

@nafg
nafg commented Nov 4, 2012
@eltimn
Lift Web Framework member
eltimn commented Nov 4, 2012

I like it. If people would prefer traits like the Mapper ones, they could just use these to make them. Or I could maybe provide both types of traits.

@Shadowfiend
Lift Web Framework member
@lkuczera
Lift Web Framework member
lkuczera commented Nov 4, 2012

Here is our CreatedUpdated:

trait CreatedUpdated[OwnerType <: CreatedUpdated[OwnerType]] extends MongoRecord[OwnerType] {
    self: OwnerType =>

  var updateUpdated = true

  def ignoreUpdatedDate = {
    updateUpdated = false
    this
  }

  object createdAt extends DateField(this)
  object updatedAt extends DateField(this) with LifecycleCallbacks {
    override def beforeSave() = if (updateUpdated) this(Helpers.now)
  }
}

I don't use this var but something like that might be useful. (someone else contributed it)

@eltimn eltimn changed the title from Added updatedAt and createdAt traits to Record to Add updatedAt and createdAt traits to Record May 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.