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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:11:30+00:00 2026-06-06T11:11:30+00:00

Need some help with Activerecord Querying in a has_many :through association. Model: Job class

  • 0

Need some help with Activerecord Querying in a has_many :through association.

Model:

Job

class Job < ActiveRecord::Base
  has_many :job_metadata, :dependent => :destroy
  has_many :metadata, :through => :job_metadata

Metadatum

class Metadatum < ActiveRecord::Base
  attr_accessible :description, :metadata_type_id
  has_one :metadatum_type
  has_many :job_metadata, :dependent => :destroy
  has_many :jobs, :through => :job_metadata

MetadatumType

class MetadatumType < ActiveRecord::Base
  attr_accessible :description
  has_many :metada

JobMetadatum

class JobMetadatum < ActiveRecord::Base
  attr_accessible :job_id, :metadatum_id
  belongs_to :job
  belongs_to :metadatum

In the console, I can run:

@job.metadata

which returns

=> [#<Metadatum id: 2, description: "Part Time", metadatum_type_id: 1, created_at: "2012-06-23 20:42:14", updated_at: "2012-06-23 20:42:14">] 

But how would I return the metadatum_id on @jobs.metadata which have a metadatum_type_id = 1?

I’m trying this:

@job.metadata.metadatum_id.where('metadata.metadatum_type_id' => 1)

But getting the following error:

NoMethodError:   Metadatum Load (0.3ms)  SELECT "metadata".* FROM 
"metadata" INNER JOIN "job_metadata" ON "metadata"."id" = 
"job_metadata"."metadatum_id" WHERE "job_metadata"."job_id" = 31
undefined method `metadatum_id' 
for #<ActiveRecord::Relation:0x007f7fb3188de8>
  • 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-06T11:11:34+00:00Added an answer on June 6, 2026 at 11:11 am

    try this

    @the_metadatum_record = @job.metadata.where("metadatum_type_id = 1").first
    

    This searches through the Metadatum records that belong to @job, and looks through those records to find ones that have metadatum_type_id of 1.

    Then the id can be accessed like @the_metadatum_record.id

    The “first” is added to the end because if your job has more than one metadatum of type 1, the query will return all of them.

    Also, I agree with Michael, those are kind of terrible names for tables…

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

Sidebar

Related Questions

I need some help in thinking through the process to do batch update on
I need some help over here to understand how the model relationship works on
I have 4 models: transac, transac_data, item, dvd_details class Transac < ActiveRecord::Base has_many :transac_datas
I have the following models set up: class Player < ActiveRecord::Base has_many :game_players has_many
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help gathering thoughts on this issue. Our team is moving ahead with
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help assigning a mouseover event to display some icons that start out

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.