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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:19:03+00:00 2026-06-13T14:19:03+00:00

I have the following model classes… class Image < ActiveRecord::Base attr_accessible :description, :title has_many

  • 0

I have the following model classes…

class Image < ActiveRecord::Base
  attr_accessible :description, :title
  has_many :imageTags
  has_many :tags, :through => :imageTags
end

class Tag < ActiveRecord::Base
  attr_accessible :name
  has_many :imageTags
  has_many :images, :through => :imageTags
end

class ImageTag < ActiveRecord::Base
  attr_accessible :position
  belongs_to :image
  belongs_to :tag
end

And when I use find for getting the Tag with the id 1

t = Tag.find(1);
@images = t.images;

But when I do the same with where, I get a NoMethodError, with the description undefined method 'images':

t = Tag.where(:name => "foo");
@images = t.images;

I also tried adding .includes(:images) before the .where statement, but that doesn’t work too. So, how can I get all Images that belong to a Tag?

  • 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-13T14:19:04+00:00Added an answer on June 13, 2026 at 2:19 pm

    .where returns an ActiveRecord::Relation instance, not a single object. Tack on a .first to grab (presumably) the only record returned:

    t = Tag.where(name: "foo").first
    @images = t.images
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes in my ActiveRecord model: def Property < ActiveRecord::Base #
I have the following model classes: @Entity @Table(name = title) public final class Title
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have the following classes in my Model: public abstract class Entity : IEntity
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)
The scenario Suppose I have the following two model classes: public class ProductColor {
In my domain model I have following Classes.A 'UserProfile' has one 'SecurityPrincipal' class SecurityPrincipal{
I’m developing MVC application and I have following classes in my model: public class
Let's say I have the following two classes: package example.model; public class Model {
Let's say I have following ORM classes (fields removed to simplify): class Animal(models.Model): say

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.