A relationship question

I have 3 tables; Feelings, Users, and Members. Both Feelings and Members
belongs_to Users with user_id.

Both models Feelings and Members have belongs_to :user in them. Feelings
has has_one :member, :through => :user.

Is this the right setup? How can I make a rails search condition in
Feelings and get a column from members into that search?

On 12 March 2011 12:59, Paul B. [email protected].invalid wrote:

I have 3 tables; Feelings, Users, and Members. Both Feelings and Members
belongs_to Users with user_id.

Both models Feelings and Members have belongs_to :user in them. Feelings
has has_one :member, :through => :user.

The above would be easier for us (well, me anyway) to understand if
you showed the class definitions
feeling.rb
class Feeling < ActiveRecord::Base
belongs_to :user

and so on. Also tell us the file names. Copy and paste from your
code in case of typo errors.

Is this the right setup? How can I make a rails search condition in
Feelings and get a column from members into that search?

I am not exactly sure what you want, but once you find Feeling object
@feeling = Feeling.first for example, then, if the relationships are
correct, the member can be accessed by
@feeling.member
so columns can be accessed by
@feeling.member.name or whatever.

You can check whether it is working by using the rails console and
typing things like
f = Feeling.first
f.member
f.member.name

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs