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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:52:37+00:00 2026-05-11T11:52:37+00:00

Here are my models: class Deck < ActiveRecord::Base belongs_to :game has_many :deck_cards end class

  • 0

Here are my models:

class Deck < ActiveRecord::Base   belongs_to :game   has_many :deck_cards end  class DeckCard < ActiveRecord::Base   belongs_to :card   belongs_to :deck end  class Card < ActiveRecord::Base end 

Here’s my attempted find:

DeckCard.all :joins => [:card, :deck], :conditions => {{:decks => {:game_id => @game.id}}, {:cards => {:present => true}}} 

I keep getting the error : undefined method for all for #Class:0x4b2a98>. I’m assuming this is a misleading error from parsing my conditions. I’m following the guide for Active Record Query. I wasn’t sure about whether to use the singular or plural form of the associations. Look like with a belongs_to, you’re supposed to use singular form in the :joins hash, but I wasn’t sure in the :conditions hash, so I tried both and neither worked.

In case it isn’t clear, what I’m trying to do in SQL is:

SELECT * from DeckCards   INNER JOIN decks on decks.id = deck_cards.deck_id   INNER JOIN cards on card.id = deck_cards.card_id   WHERE decks.game_id = 4   AND cards.present = true 

I’m able to get around it for now by using DeckCard.find_by_sql, but it would be nice to figure out why the joins and conditions on associations isn’t working.

I’m using InstantRails-2.0 on windows, which is using Rails 2.0.2

Edited : some progress using DeckCard.find(:all ...) instead. I also edited the brackets based on another answer. My latest code is

DeckCard.find :all, :joins => [:card, :deck], :conditions => {:deck => {:game_id => @game.id}, :cards => {:present => true}}   

which is producing the following error:

Unknown column 'deck_cards.decks' in 'where clause': SELECT `deck_cards`.* FROM `deck_cards`   INNER JOIN `cards` ON `cards`.id = `deck_cards`.card_id  INNER JOIN `decks` ON `decks`.id = `deck_cards`.deck_id  WHERE (`deck_cards`.`decks` = '--- \n- :game_id\n- 5\n' AND `deck_cards`.`cards` = '--- \n- :present\n- true\n')   

The joins appear correct but not the WHERE conditions. I’ve tried a few different things like :deck or :decks in the conditions clause but no luck. Could this be another difference between the current ActiveRecord Query Interface docs and how conditions are done in 2.0.2?

Thanks!

  • 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. 2026-05-11T11:52:38+00:00Added an answer on May 11, 2026 at 11:52 am

    You need to complete your association with the Card model:

    class Card < ActiveRecord::Base   has_many :deck_cards end 

    EDIT 2: Try this:

     DeckCard.find :all, :joins => [:card, :deck], :conditions => ['decks.game_id = ? and cards.present = ?', @game.id, true] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The abuse of static classes can be considered bad practice.… May 12, 2026 at 10:03 am
  • Editorial Team
    Editorial Team added an answer This jQuery plugin looks like it will do the trick:… May 12, 2026 at 10:03 am
  • Editorial Team
    Editorial Team added an answer Why not get the Feedapi, along with feedapi mapper, and… May 12, 2026 at 10:03 am

Related Questions

I'm building an app in Ruby on Rails, and I'm including 3 of my
I'm having an error where I am not sure what caused it. Here is
I'm developing a web app using Django, and I'll need to add search functionality
I'm currently learning Django and some of my models have custom methods to get

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.