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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:49:55+00:00 2026-05-20T17:49:55+00:00

I have a limited set of objects (20 – 30) which I need to

  • 0

I have a limited set of objects (20 – 30) which I need to be able to combine with ActiveRecord Objects. Putting them into the DB just seems awful because I already have two other join models hooked up to the model.

So let’s say i have a class

class Thing < ActiveRecord::Base
  has_many :other_things, :class_name => 'OtherThing'
end

with an existing table. How would I be able to combine this with a class not inheriting from ActiveRecord (here’s my best guess)

class OtherThing < ActiveRecord::Base
  OtherThing = Struct.new(:id, :name, :age, :monkey_fighting_ability)
  belongs_to :thing, :class_name => 'Thing'

  validate :something

  def self.search_for(something)
    MY_GLOBAL_HASH[something].map do |hash|
      instance = OtherThing.new
      hash.each_pair do |k,v|
        instance.send(:"#{k}=", v)
      end
      instance
    end
  end

  #if AR wants to call save
  def save
    return true
  end
  alias save save!

  protected
    def something
      self.errors.add(:monkey_fighting_ability, 'must be unlimited') if self.class.search_for(something).empty?
    end
end

Point being that I want to use ActiveRecord methods and so on without ever hitting the db. Help is greatly appreciated.

  • 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-20T17:49:55+00:00Added an answer on May 20, 2026 at 5:49 pm

    I’d suggest reading the post on “Make any Ruby Object Feel Like An Active Record” by Yehuda Katz. It goes over how to convert any object into a model-like class, without the database backing.

    Good Luck!

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

Sidebar

Related Questions

I have a client which makes a limited number of concurrent web requests. I
I need advice on how to return a limited set of data from an
For example I have limited space and I want the submit button to appear
As everybody knows, you have limited precision when you use printf to output the
I have a query limited by a date range: select * from mytable where
I have an jQuery.autocomplete field presenting a limited range of decimal numbers. Ex: var
In my limited experience, I've been on several projects that have had some sort
Excuse my limited knoweldge here. In the past I have used Steve Sanderson's method
Note: This issue appears to be limited to SQL Server 2005 SP2 I have
Excuse my ignorance. My knowledge of regular expressions is extremely limited. I have the

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.