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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:35:49+00:00 2026-06-13T12:35:49+00:00

Here is what I’m attempting to do: class Account < ActiveRecord::Base def name end

  • 0

Here is what I’m attempting to do:

class Account < ActiveRecord::Base
   def name
   end
end

class TypeA < Account
end

class TypeB < Account
end

Where TypeA and TypeB are stored on two distinct tables and Account acts pretty much as an abstract interface (with no table associated). They both have large number of entris and large number of fields so I want to keep them separated. Is there a way to go for this ?

(The exemple above does not work as a table for account is expected btw).

UPDATE

Now, if I use modules (as suggested in the answers), that raises another problem:

Let’s say I have

class Transaction < ActiveRecord::Base
   belongs_to :account, :polymorphic => true
end

where account can be TypeA or TypeB. I get the following misbehavior:

i = TypeA.new(:name => "Test")
t = Transaction.new(:account => i)
t.account.name
>> nil

which is not what I want as account.name should return “Test”. How to get this?

  • 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-13T12:35:50+00:00Added an answer on June 13, 2026 at 12:35 pm

    Use module instead. You have shared behavior between those two models that you want to share. That’s a great use-case for modules.

    # inside lib/account.rb
    module Account
       # ...
       def name
         # code here
       end
       # ...
    end
    
    # inside app/models/type_a.rb
    class TypeA < ActiveRecord::Base
      include Account
    end
    
    # inside app/models/type_b.rb
    class TypeB < ActiveRecord::Base
      include Account
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here is an example: I have the generic type called Account. I wish to
Here is the problem that I am trying to solve. I have two folders
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here is my problem.. I have the option to create(add) two new input fields,
Here's the two scenarios. We are using a manually built xml soap request with
Here is my code, which takes two version identifiers in the form 1, 5,
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:

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.