Hi all,
Recently i am upgrading one of my rails app to 3.2.6. It seems
the dafault_scope with options has been deprecated.
i have a scope like this default_scope :include => [:campaign, :site],
:order => :'sites.name' in a relational model campaign_site
which giving this error

Mysql2::Error: Unknown column 'sites.name' in 'order clause': SELECT `campaigns`.* FROM `campaigns` INNER JOIN `campaign_sites` ON `campaigns`.`id` = `campaign_sites`.`campaign_id` WHERE `campaign_sites`.`site_id` = 11377 ORDER BY campaigns.name, sites.name

Any idea how to get around this?

Thanks in advance!


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zdecvl86inwJ.
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-US.

Search Discussions

  • Sam Serpoosh at Jun 29, 2012 at 1:50 pm
    Perception 1:
    I'm not sure but according to the Sql Query that you put here it seems that
    there's a table in your application database called
    "campaign_sites" not "sites" (or maybe you have another table sites which
    can't be perceived from this report here or you're doing
    kind of an aliasing or something!) and if you wanted to order by the name
    of a campaign site I think you should change
    the "sites.name" to "campaign_sites.name"

    Because this query seems straightforward you joined the campaign and
    campaign_site on the campaign_id (according to your has_many|belongs_to
    association)
    and then you want the result to be ordered by campaign_site's name I guess.

    Perception 2:
    The other perception here form the Sql Query and more specifically the part
    -> "campaign_sites.site_id = 11377" is that site_id is a foreign key to a
    sites table
    in your campaign_sites table and if that's the case because you didn't
    include the "sites" table in your JOIN mechanism then it can't find
    sites.name cause
    there is no sites in the query join result from your tables. (you only have
    tables -> campaigns and campaign_sites in the JOIN)

    Hope that helps. But I think a little more explanation about your model
    relationships (campaign, campaign_sites, [sites if there's such a thing])
    can be helpful so we can understand the problem better and maybe
    give you better answers.

    Good Luck ;)

    --
    Sam Serpoosh
    Software Developer: http://masihjesus.wordpress.com
    Twitter @masihjesus <http://twitter.com/masihjesus>

    --
    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-US.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 29, '12 at 9:55a
activeJun 29, '12 at 1:50p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Venkata reddy: 1 post Sam Serpoosh: 1 post

People

Translate

site design / logo © 2022 Grokbase