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 9204319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:41:07+00:00 2026-06-17T23:41:07+00:00

I have a model: class Reservation < ActiveRecord::Base # amount_received :integer # event_id :integer

  • 0

I have a model:

class Reservation < ActiveRecord::Base
  #  amount_received :integer
  #  event_id        :integer
  #  confirmed_at    :datetime
  belongs_to :event

I’d like to do something like:

`self.confirmed_at = Time.zone.now if amount_received >= event.price`

in the model whenever amount_received is changed (or I suppose whenever model is saved?). But not sure where to put this in a Rails app?

It sort of wants to be in the model because it is changing the state of the model BUT it depends on a value in a related model event.price and event means nothing in the model. Do I really want to query the DB for Event.find(event_id) in the model of another object?

Set me straight, thanks!

  • 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-17T23:41:08+00:00Added an answer on June 17, 2026 at 11:41 pm

    There are two easy options…

    Me personally, since this model has a defined relation and needs to know about it, I’d put it in a pre save callback and be done with it. However if you are concerned with keeping one model independent of another, you could also place this in an observer. That way, you could have a separate object which merely observes the reservation and deals with the other relationship. I would personally not opt to go that route, however, since what you are updating is a property of the reservation model and I think it’s entirely reasonable that your reservation model be aware of the event and know how to respond to event properties.

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

Sidebar

Related Questions

I have model: class RealtyPhoto < ActiveRecord::Base attr_accessible :name, :photo mount_uploader :photo, RealtyPhotoUploader belongs_to
I have my model class class Location < ActiveRecord::Base belongs_to :post attr_accessor :address, :category,:name,:postcode,:tel
I have this model: class Location < ActiveRecord::Base acts_as_gmappable def gmaps4rails_address #{self.city}, #{self.country} end
I have following model: class Customer < ActiveRecord::Base has_one :cart end class Cart <
I have a model: class HelloRails < ActiveRecord::Base attr_accessible :filename, :filevalidate include In4systemsModelCommon validates
I have this model: class Story < ActiveRecord::Base validates_presence_of :name , :link end Where
I have a model: class Topic < ActiveRecord::Base define_index do indexes title, :sortable =>
I have model: class Topic < ActiveRecord::Base attr_accessible :title, :description has_many :comments, :dependent =>
I have a model: class Item < ActiveRecord::Base Item has a property 'store' Based
I have model User class User < ActiveRecord::Base has_and_belongs_to_many :roles attr_accessible :login, :email, :password,

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.