Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:51:58+00:00 2026-06-15T04:51:58+00:00

ActiveRecord handle timestamps doing something like this: Inserting data? created_at is defined Updating data?

  • 0

ActiveRecord handle timestamps doing something like this:

  • Inserting data? created_at is defined
  • Updating data? updated_at is redefined

How would I do it using SORM?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:51:59+00:00Added an answer on June 15, 2026 at 4:51 am

    At a first glance something like this could work:

    import org.joda.time._
    object Db extends Instance (entities = ...) {
      override def save [T <: AnyRef : TypeTag] ( v : T ) 
        = v match {
            case v : Artist with Persisted =>
              super.save( v.copy( updatedAt = DateTime.now() ) )
            case v : Artist =>
              super.save( v.copy( createdAt = DateTime.now() ) )
            // ... so on for other entities
            case v =>
              super.save(v)
          }
    }
    

    But then how would you create those artist instances from scratch? Should those date fields be assigned with messy nulls or null-ish date values or should they maybe get wrapped in Options? Well, either of those should solve the problem, but here is another option:

    import org.joda.time._
    case class Artist 
      ( name : String, 
        updatedAt : DateTime = DateTime.now(),
        createdAt : DateTime = DateTime.now() )
    
    object Db extends Instance (entities = ...) {
      override def save [T <: AnyRef : TypeTag] ( v : T ) 
        = v match {
            case v : Artist with Persisted =>
              super.save( v.copy( updatedAt = DateTime.now() ) )
            case v =>
              super.save(v)
          }
    }
    

    I gotta tell you the whole problem doesn’t feel very natural to me. I can’t imagine scenarios where that kinda behaviour would be benefitial. But then again I’ve presented you the options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a RoR website and would like to handle server errors
I have two models like this: class Topic < ActiveRecord::Base has_many :articles end class
I would like to know if it's possible to write a migration instead of
I handle RecordNotFound error in my application_controller.rb as follow: rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
I am using Ruby on Rails 3 and I would like to update an
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I am using Ruby on Rails 3.2.2 and I would like to know what
Does the ActiveRecord template files create classes that handle many to many relationships?
What is the best way to handle a static data set (non-dynamic)? For instance,
I have an ActiveRecord Model, PricePackage. That has a before_create call back. This call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.