Message from discussion
Add a last updated timestamp on all my mongo collections
Received: by 10.58.229.232 with SMTP id st8mr951137vec.34.1352378167137;
Thu, 08 Nov 2012 04:36:07 -0800 (PST)
X-BeenThere: liftweb@googlegroups.com
Received: by 10.52.67.52 with SMTP id k20ls3090995vdt.1.gmail; Thu, 08 Nov
2012 04:36:02 -0800 (PST)
Received: by 10.52.65.33 with SMTP id u1mr1640196vds.18.1352378162632;
Thu, 08 Nov 2012 04:36:02 -0800 (PST)
Date: Thu, 8 Nov 2012 04:36:02 -0800 (PST)
From: bg <brentgra...@gmail.com>
To: liftweb@googlegroups.com
Message-Id: <867d598e-a1db-48dd-b279-1aca03a80742@googlegroups.com>
In-Reply-To: <c6bd3e84-9bd7-4ab6-bad4-a5bae1fabf38@googlegroups.com>
References: <a7427ca2-7286-44f4-9be2-a1e6247f4be9@googlegroups.com>
<90df47a0-c1a9-4efa-a400-feef4705c0d0@googlegroups.com>
<a39c83ca-3b89-4547-a9e7-ef3fed740bbf@googlegroups.com>
<c6bd3e84-9bd7-4ab6-bad4-a5bae1fabf38@googlegroups.com>
Subject: Re: Add a last updated timestamp on all my mongo collections
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2525_2233818.1352378162214"
------=_Part_2525_2233818.1352378162214
Content-Type: multipart/alternative;
boundary="----=_Part_2526_29940711.1352378162214"
------=_Part_2526_29940711.1352378162214
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Brilliant - thank you very much, working on the create and saves.
On Saturday, November 3, 2012 12:26:19 PM UTC, Tim Nelson wrote:
>
> Hi again,
>
> You probably wanted a trait, so here's one that works. I will probably be
> adding this to Record at some point.
>
> trait Updated[T <: Updated[T]] extends Record[T] {
> self: T =>
>
> /**
> * The updatedAt field. You can change the behavior of this
> * field:
> * <pre name="code" class="scala">
> * override lazy val updatedAt = new MyUpdatedAt(this) {
> * override def dbColumnName = "i_eat_time_for_breakfast"
> * }
> * </pre>
> */
> lazy val updatedAt: MyUpdatedAt = new MyUpdatedAt(this)
>
> protected class MyUpdatedAt(obj: T) extends
> DateTimeField(obj.asInstanceOf[T]) with LifecycleCallbacks {
> override def beforeSave() {
> super.beforeSave
> this.set(Calendar.getInstance)
> }
> }
> }
>
> Tim
>
> On Saturday, November 3, 2012 7:08:25 AM UTC-5, Tim Nelson wrote:
>>
>> Hi bg,
>>
>> MongoRecord does use the LifecycleCallbacks. However, currently they only
>> work for save and delete. I will add the update callbacks to the update
>> function.
>>
>> Here's a field that should work for you with the save function:
>>
>> object updatedAt extends DateTimeField(this) with LifecycleCallbacks {
>> override def beforeSave() {
>> super.beforeSave
>> this.set(Calendar.getInstance)
>> }
>> }
>>
>> Tim
>>
>> On Friday, November 2, 2012 5:20:26 AM UTC-5, bg wrote:
>>>
>>> there is a package net.liftweb.record.LifecycleCallbacks
>>>
>>> So I guess LifecycleCallbacks does exist within the Record world, but is
>>> it the case that MongoRecord doesn't use them?
>>>
>>> On Wednesday, October 31, 2012 9:02:26 PM UTC, bg wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I would like to create a "last updated" timstamp across all my
>>>> collections.
>>>>
>>>> My model classes look like
>>>>
>>>> class User extends MongoRecord[User] with MongoId[User] {
>>>>
>>>> ....
>>>>
>>>> object User extends User with MongoMetaRecord[User] {
>>>>
>>>> ....
>>>>
>>>> Any suggestions, or examples on a good way to implement this? Looking
>>>> for every collection to get a field which gets poptulated with the currect
>>>> time whenever a update is performed.
>>>>
>>>> Thanks
>>>>
>>>
------=_Part_2526_29940711.1352378162214
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Brilliant - thank you very much, working on the create and saves.<br><br>On=
Saturday, November 3, 2012 12:26:19 PM UTC, Tim Nelson wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
#ccc solid;padding-left: 1ex;">Hi again,<div><br></div><div>You probably w=
anted a trait, so here's one that works. I will probably be adding this to =
Record at some point.</div><div><br></div><div><div>trait Updated[T <: U=
pdated[T]] extends Record[T] {</div><div> self: T =3D></div><div><=
br></div><div> /**</div><div> * The updatedAt field. &nbs=
p;You can change the behavior of this</div><div> * field:</div>=
<div> * <pre name=3D"code" class=3D"scala"></div><div>&nb=
sp; * override lazy val updatedAt =3D new MyUpdatedAt(this) {</div><d=
iv> * override def dbColumnName =3D "i_eat_time_for_brea=
kfast"</div><div> * }</div><div> * </pre></di=
v><div> */</div><div> lazy val updatedAt: MyUpdatedAt =3D=
new MyUpdatedAt(this)</div><div><br></div><div> protected class MyUp=
datedAt(obj: T) extends DateTimeField(obj.<wbr>asInstanceOf[T]) with Lifecy=
cleCallbacks {</div><div> override def beforeSave() {</div><di=
v> super.beforeSave</div><div> this=
.set(Calendar.getInstance)</div><div> }</div><div> }</di=
v><div>}</div><div><br></div><div>Tim</div><br>On Saturday, November 3, 201=
2 7:08:25 AM UTC-5, Tim Nelson wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
">Hi bg,<div><br></div><div>MongoRecord does use the LifecycleCallbacks. Ho=
wever, currently they only work for save and delete. I will add the update =
callbacks to the update function.</div><div><br></div><div>Here's a field t=
hat should work for you with the save function:</div><div><br></div><div><d=
iv>object updatedAt extends DateTimeField(this) with LifecycleCallbacks {</=
div><div> override def beforeSave() {</div><div> super.b=
eforeSave</div><div> this.set(Calendar.getInstance)</div><div>=
}</div><div>}</div></div><div><br></div><div>Tim<br><br>On Friday, N=
ovember 2, 2012 5:20:26 AM UTC-5, bg wrote:<blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex">there is a package net.liftweb.record.<wbr>LifecycleCallbacks=
<div><br></div><div>So I guess LifecycleCallbacks does exist wit=
hin the Record world, but is it the case that MongoRecord doesn't use =
them?<br><br>On Wednesday, October 31, 2012 9:02:26 PM UTC, bg wrote:<block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div>Hi all,</div><div><br></div><div>I w=
ould like to create a "last updated" timstamp across all my collections.</d=
iv><div><br></div><div>My model classes look like</div><div><br></div><div>=
class User extends MongoRecord[User] with MongoId[User] {</div><div><br></d=
iv><div>....</div><div><br></div><div>object User extends User with MongoMe=
taRecord[User] {</div><div><br></div><div>....</div><div><br></div><div>Any=
suggestions, or examples on a good way to implement this? Looking for ever=
y collection to get a field which gets poptulated with the currect time whe=
never a update is performed.</div><div><br></div><div>Thanks</div></blockqu=
ote></div></blockquote></div></blockquote></div></blockquote>
------=_Part_2526_29940711.1352378162214--
------=_Part_2525_2233818.1352378162214--