Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Active Record Querying HABTM
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
saroj s.  
View profile  
 More options Jun 11 2012, 12:04 pm
From: "saroj s." <li...@ruby-forum.com>
Date: Mon, 11 Jun 2012 18:04:01 +0200
Local: Mon, Jun 11 2012 12:04 pm
Subject: Active Record Querying HABTM
I am new to rails and stuck on one Querying issue. Here is the
situation.

Model: Category
class Category < ActiveRecord::Base
       has_and_belongs_to_many :postings
       has_and_belongs_to_many :volunteers
end

Model: Posting
class Posting < ActiveRecord::Base
       has_and_belongs_to_many :categories
end

Model: Volunteer
class Volunteer < ActiveRecord::Base
       has_and_belongs_to_many :categories
end

-------
Now Here is the problem I am trying to solve

I want to find out all the postings of the categories that the
volunteer is interested in. The volunteer might be interested in more
than one categories and posting might be assigned more than one
categories.

Here is the basic pseudocode

 vol=Volunteer.find 1
 vol_cats=vol.categories
foreach(vol_cat in vol_cats)
{
  postings=postings + vol_cat.postings

}

Please Help me

Thank you

--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Aronson  
View profile  
 More options Jun 11 2012, 12:36 pm
From: Dave Aronson <googlegroups2d...@davearonson.com>
Date: Mon, 11 Jun 2012 12:36:05 -0400
Local: Mon, Jun 11 2012 12:36 pm
Subject: Re: [Rails] Active Record Querying HABTM

On Mon, Jun 11, 2012 at 12:04 PM, saroj s. <li...@ruby-forum.com> wrote:
> I want to find out all the postings of the categories that the
> volunteer is interested in.

Sounds like you want a "has_many :through" relationship.

-Dave

--
 Dave Aronson, Cleared/Remote Ruby on Rails Freelancer
(NoVa/DC/Remote); see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
saroj s.  
View profile  
 More options Jun 11 2012, 12:50 pm
From: "saroj s." <li...@ruby-forum.com>
Date: Mon, 11 Jun 2012 18:50:57 +0200
Local: Mon, Jun 11 2012 12:50 pm
Subject: Re: Active Record Querying HABTM
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »