Hello,

Perhaps someone knows the answer to this one, because its been
stumping me for a long time.

BTW, i'm still using rails 3.0.0, perhaps this issue is solved in a
recent release.

Here are my Models


class Team < ActiveRecord::Base
has_many :players
....
end

class Player < ActiveRecord::Base
belongs_to :team
has_many :jerseys
....
end

class Jersey < ActiveRecord::Base
belongs_to :player
....
end

In the console (or in any of my methods), I would like to list all the
Teams that have Players with Jerseys that are XL or higher

# IF I JUST WANT A COUNT OF THE TEAMS, THIS WORKS
console > Team.includes(:players => :jerseys).where("jerseys.size in
(?)",['XL',XXL']).count
console > 15

# HOWEVER, WHEN I WANT TO GET A COLLECTION IT FAILS WITH THE FOLLOWING
MESSAGE
console > Team.includes(:players => :jerseys).where("jerseys.size in
(?)",['XL',XXL']).all
## error message I receive
"ActiveRecord::ConfigurationError: Association named 'jerseys' was not
found; perhaps you misspelled it?"


What am i doing wrong? This seems like a bug, doesn't it??

Any help is appreciated!


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Craig White at Jan 5, 2012 at 10:05 pm

    On Jan 5, 2012, at 2:27 PM, loominator1970 wrote:

    Hello,

    Perhaps someone knows the answer to this one, because its been
    stumping me for a long time.

    BTW, i'm still using rails 3.0.0, perhaps this issue is solved in a
    recent release.

    Here are my Models


    class Team < ActiveRecord::Base
    has_many :players
    ....
    end

    class Player < ActiveRecord::Base
    belongs_to :team
    has_many :jerseys
    ....
    end

    class Jersey < ActiveRecord::Base
    belongs_to :player
    ....
    end

    In the console (or in any of my methods), I would like to list all the
    Teams that have Players with Jerseys that are XL or higher

    # IF I JUST WANT A COUNT OF THE TEAMS, THIS WORKS
    console > Team.includes(:players => :jerseys).where("jerseys.size in
    (?)",['XL',XXL']).count
    console > 15

    # HOWEVER, WHEN I WANT TO GET A COLLECTION IT FAILS WITH THE FOLLOWING
    MESSAGE
    console > Team.includes(:players => :jerseys).where("jerseys.size in
    (?)",['XL',XXL']).all
    ## error message I receive
    "ActiveRecord::ConfigurationError: Association named 'jerseys' was not
    found; perhaps you misspelled it?"


    What am i doing wrong? This seems like a bug, doesn't it??

    Any help is appreciated!
    ----
    clearly not a bug... Just off the top of my head, this looks more like a failure to associate.

    class Team
    has_many :players
    has_many :jerseys, :through => :players
    end

    but I think in the end, you will find that using scopes is very handy

    Craig

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Loominator1970 at Jan 5, 2012 at 10:23 pm
    Awesome, thanks for the help, i appreciate it!

    Dave
    On Jan 5, 3:05 pm, Craig White wrote:
    On Jan 5, 2012, at 2:27 PM, loominator1970 wrote:








    Hello,
    Perhaps someone knows the answer to this one, because its been
    stumping me for a long time.
    BTW, i'm still using rails 3.0.0, perhaps this issue is solved in a
    recent release.
    Here are my Models
    class Team < ActiveRecord::Base
    has_many :players
    ....
    end
    class Player < ActiveRecord::Base
    belongs_to :team
    has_many :jerseys
    ....
    end
    class Jersey < ActiveRecord::Base
    belongs_to :player
    ....
    end
    In the console (or in any of my methods), I would like to list all the
    Teams that have Players with Jerseys that are XL or higher
    # IF I JUST WANT A COUNT OF THE TEAMS, THIS WORKS
    console > Team.includes(:players => :jerseys).where("jerseys.size in
    (?)",['XL',XXL']).count
    console > 15
    # HOWEVER, WHEN I WANT TO GET A COLLECTION IT FAILS WITH THE FOLLOWING
    MESSAGE
    console > Team.includes(:players => :jerseys).where("jerseys.size in
    (?)",['XL',XXL']).all
    ## error message I receive
    "ActiveRecord::ConfigurationError: Association named 'jerseys' was not
    found; perhaps you misspelled it?"
    What am i doing wrong?  This seems like a bug, doesn't it??
    Any help is appreciated!
    ----
    clearly not a bug... Just off the top of my head, this looks more like a failure to associate.

    class Team
    has_many :players
    has_many :jerseys, :through => :players
    end

    but I think in the end, you will find that using scopes is very handy

    Craig
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 5, '12 at 9:27p
activeJan 5, '12 at 10:23p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Loominator1970: 2 posts Craig White: 1 post

People

Translate

site design / logo © 2021 Grokbase