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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:13:22+00:00 2026-06-13T08:13:22+00:00

class Participant has_many :cells end class Round has_many :cells end class Question has_many :cells

  • 0
class Participant
  has_many :cells
end

class Round
  has_many :cells
end

class Question
  has_many :cells
end

class Cell
   belongs_to :participant
   belongs_to :question
   belongs_to :Round
end

a = an instance of Participant, Question or Round
b = an instance of Participant, Question or Round

I would like to write an iteration across all instances of Cell that belong to the indicated a and b. I know that a and b are not instances of the same class, but I don’t know ahead of time which one they are.

I guess I could write:

if a.class == Participant && b.class == Question
  Cell.select(participant_id: a.id, question_id: b.id).each do 
  ... and so on

But that is really ugly. I think there must be somehow to use the join method but I haven’t been able to figure it out.

  • 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-13T08:13:23+00:00Added an answer on June 13, 2026 at 8:13 am

    Try:

    Cell.where(:"#{a.class.to_s.underscore}_id": a.id, :"#{b.class.to_s.underscore}_id": b.id).each do |cell|
      # your code
    end
    

    But I’m pretty sure that there is nicer way.

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

Sidebar

Related Questions

class Users < ActiveRecord::Base has_many :meetings, :through => :meeting_participations has_many :meeting_participations end class Meetings
I'm working on a Grails application. There is a domain class participant - within
I have a class that contains this class method: def self.get_event_record(row, participant) event =
In the command pattern: Why shouldn't the client participant be the same class as
class A attr_accessor :dab .... end Now I have an array of instances of
What would the cleanest way to the following pseudocode be? class Player id name
I have the following models: class EventParticipant < ActiveRecord::Base belongs_to :event has_one :user attr_accessible
I am using Djangos default authentication system (django.contrib.auth) and I would like to add
Given the following code : public abstract class Participant { private String fullName; public
I would like to have a custom snippet of html form code that takes

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.