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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:55:25+00:00 2026-06-05T03:55:25+00:00

I have these models: class Segment < ActiveRecord::Base has_many :families, :foreign_key => :segment_code, :primary_key

  • 0

I have these models:

class Segment < ActiveRecord::Base
  has_many :families, :foreign_key => :segment_code, :primary_key => :code
end

class Family < ActiveRecord::Base
  belongs_to :segment, :foreign_key => :segment_code, :primary_key => :code
  has_many :genus, :foreign_key => :family_code, :primary_key => :code
end

class Genus < ActiveRecord::Base
  belongs_to :family, :foreign_key => :family_code, :primary_key => :code
  has_many :commodities, :foreign_key => :genus_code, :primary_key => :code
end

class Commodity < ActiveRecord::Base
  belongs_to :genus, :foreign_key => :genus_code, :primary_key => :code
end

And I get this error when calling this sequence of rails console irb commands, i’m lost please help. I’m also thinking I might need to use has many :through. critiques on my data model are welcome also.

This is the error: NameError: uninitialized constant Family::Genu

irb(main):003:0> @genus = Genus.first
  ←[1m←[35mGenus Load (15.6ms)←[0m  SELECT `genus`.* FROM `genus` LIMIT 1
=> #<Genus key: 100003, family_code: 10100000, code: 10101500, title: "Livestock", defintion: nil>
irb(main):004:0> @genus.family
  ←[1m←[36mFamily Load (0.0ms)←[0m  ←[1mSELECT `families`.* FROM `families` WHERE `families`.`code` = 10100000 LIMIT 1←[0m
=> #<Family key: 100002, segment_code: 10000000, code: 10100000, title: "Live animals", definition: nil>
irb(main):005:0> @family = @genus.family.first
NoMethodError: undefined method `first' for #<Family:0x2621a60>
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods.rb:60:in `method_missing'
        from (irb):5
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
irb(main):006:0> @family = @genus.family
=> #<Family key: 100002, segment_code: 10000000, code: 10100000, title: "Live animals", definition: nil>
irb(main):007:0> @family.genus
NameError: uninitialized constant Family::Genu
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1335:in `compute_type'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/reflection.rb:173:in `klass'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/association.rb:118:in `klass'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/association.rb:166:in `find_target?'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:323:in `load_target'
        from C:in `load_target'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
irb(main):008:0>
  • 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-05T03:55:27+00:00Added an answer on June 5, 2026 at 3:55 am

    It is confused by the plural form of Genus/Genera (not Genu/Genus), and is removing the ‘s’ to singularize. Fix this in the config/initializers/inflections.rb

    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular 'genus', 'genera'
    end
    

    In which case you need to change your has_many:

    class Family < ActiveRecord::Base
      belongs_to :segment, :foreign_key => :segment_code, :primary_key => :code
      has_many :genera, :foreign_key => :family_code, :primary_key => :code
    end
    

    Or you can do this, which is not correct English, but would make your existing code work:

    ActiveSupport::Inflector.inflections do |inflect|
      inflect.uncountable %w( genus )
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have these models class Project < ActiveRecord::Base has_many :comments end class Comment
I have these 3 models: class Car < ActiveRecord::Base belongs_to :user has_many :car_styles has_many
I have these two models class Invoice < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items ...
I have these models (psuedocode): class Order has_many :line_items end class LineItem belongs_to :purchasable,
ruby 1.9.2p290 rails 3.1.1 I have these models: class Recipe < ActiveRecord::Base belongs_to :festivity
I have these models: Person has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages has_many
I have these models: class Person(models.Model): name=models.CharField(max_length=100) family=models.CharField(max_length=100) class MailContact(models.Model): person=models.ForeignKey(Person) email=models.CharField(max_length=100) #some fields
I have these two models : class Module(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(unique=True,
I have these models: class Model1(models.Model): ... class Model2(models.Model): m1 = models.OneToOneField(Model1, related_name='m2') ...
I have these models: class UserProfile(models.Model): user = models.OneToOneField(User) #etc class Organization(models.Model): users =

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.