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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:15:11+00:00 2026-05-26T16:15:11+00:00

I have two tables: stores raw_stores_data The raw_stores_data is received from a third party

  • 0

I have two tables:

stores
raw_stores_data

The raw_stores_data is received from a third party daily.

I’d update certain fields of the stores model if those fields have been modified for that record in raw_stores_data.

Currently I have a bunch of conditional statements that check each of those fields. Is there any better way to code this?

new_data = raw_stores_data.all.select do |item|
   item.store_id.present?
end

new_data.each do |item|
  if item.field1 != item.stores.field1
  ...
  ...
  ...

  # update record with hash of fields to update created above
end
  • 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-05-26T16:15:12+00:00Added an answer on May 26, 2026 at 4:15 pm

    You could add an association and special mutators to the ‘raw’ model that know how manipulate the ‘stores’ object. This serves to keep the model code in the model. Thin controller, comprehensive models, etc.

    class Store < ActiveRecord::Base
      has_one :raw_stores_data
    end
    
    
    class RawStoresData < ActiveRecord::Base
      belongs_to :store
    
      def field1=(value)
        store.field1 = value
        store.save!
        field1 = value
      end
    end
    

    I’m hand waving at some of the details, and you might want to reverse the direction of the association or make it go both directions.

    EDIT:

    You would use this as such:

    raw_data = RawStoreData.find(param[:id]) # or new or however you get this object
    raw_data.field1 = param[:field1]
    

    The act of assigning will use the ‘field1=’ method, and make the change to the associated store object. If you’re worried about saving unnecessarily, you could conditionalize in that method to only save if the value changed.

    I hope this is clearer.

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

Sidebar

Related Questions

I have two tables - users and stores . there is a third table
I have two tables, one stores the products and quantity we have bought, the
I have two tables, both with start time and end time fields. I need
I have two tables: Stores and Items. The relationship is: Stores 1---* Items In
I have two tables, one stores user sessions and the other stores shopping cart
I have two tables, one that stores serial number uut_build , and another for
I have two tables inside a database. One stores unique userNames and a unique
I have two tables, one that stores user earnings and another that stores the
I have two tables. One with information about properties. The other stores 3 images
I want to create a table that stores values from two different tables; From

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.