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

  • SEARCH
  • Home
  • 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 8848919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:31:02+00:00 2026-06-14T12:31:02+00:00

I’m working on this requirement: I have an object-relational model quite big, where entities

  • 0

I’m working on this requirement: I have an object-relational model quite big, where entities are very strongly linked. Let us use, as example, this relationship: a building has many apartments, an apartment has many divisions. Now, what I want: when something changes on any division, I want to “inform” the building, or better, mark the building has being “updated” or “modified”.

  • Current solution: we have a self-written implementation in which we would mark division as “affecting” building, and building’s “modified” timestamp would be updated each time a division would be updated.

  • Desired solution: an already existing “out-of-the-box” implementation (a gem, a plugin, God, perhaps) which would spare us the work of refactoring our implementation.

  • Unwanted solution: please, don’t tell me to mark all these associations with :autosave => true. I would like a solution which is queueable.

Solutions which do not comprise the desired solution but are either suggestions to improve the performance of the current solution are of course welcome as well. In lack of a desired solution we will most definitely improve on the existing one.

A small edit:

This behaviour has to be generic. It’s not only for buildings cases, but any model with associations can have this behaviour. Which will always be the same: fetch affected associations and update them. Now, I don’t want to write different observers with the same routine.

On the performance issue: Updated affected association updates must also trigger its affected associations. Now, let’s imagine 1 building affects 100 divisions, and each division affects 100 chairs. Now, the observer solution works only on the business level. That is, I have to instantiate every AR instance so that the observers can act. Which I hold as bad performance. If A affects 100 Bs, I do it with one DB statement. But how can the observers for these 100 be triggered when I do it all with SQL?

So, back to the main update points: this behaviour is generic, and most importantly, the performance has to be top (associations may trigger nxn updates for has_many associations, for instance).

  • 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-14T12:31:03+00:00Added an answer on June 14, 2026 at 12:31 pm

    So, the way I solve it was a mixture of the various suggestions concerning observer design pattern implementations. So, to start, none of the base implementations of the pattern work for me. Why? I wanted to have the concept of a model A observing its relation B, B being observed by its relation A, and the routine of this observation being defined somewhere else, in a (lets call it that) notifier.

    Why couldn’t I use Ruby ‘observer’ library? In theory I could have achieved that, but the observed objects call a method called “changed” to notify its observers, and “changed” is a method which is overwritten by ActiveRecord, namely by the “dirty” library.

    Why couldn’t I use AR ‘observers’? Because here the observer is what I want the notifier to be. The routine is not implemented in the model, but i couldn’t say which other AR models have to be notified. This was an hinderance.

    How did I solve it? I created a library myself, using the ActiveModel::Observing library, which allowed me to implement the functionality I wanted. I designed to I would have this DSL:

    class A < ActiveRecord
    has_one :b

     observes :b, :on => :create, :notifiers => :update_observer
    

    end

    So this means, when b gets created, there is a notifier update_observer which can reach b and a and do something with it. so, in this case:

    class UpdateObserverNotifier < Notifier
    
      def action(observable, observer)
        observer.update_attributes(updated_at: observable.updated_at)
      end
    end
    

    the DSL call on the observer will inject ‘observer’ and ‘observable’ behaviour in the respective classes. The Notifier base class will have notification behaviour, and it will have access to both the observable and the observer object, in case something from the observable has to be mirrored in the observer. And if your action triggers callbacks on the observer, it will also notify potential observers of the observer itself.

    Yup, so this was it. Thanks for the suggestions, otherwise I wouldn’t have achieved it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.