Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails 2.2.2 looking for column that does not exist

#1833

Hi, I recently upgraded from Rails 2.0.2 to 2.1.2 with no problems, then I moved from 2.1.2 to 2.2.2 and have been noticing this strange error.

Mysql::Error: Unknown column 'domain_listings.id' in 'field list': SELECT domain_listings.id FROM domain_listings WHERE (domain_listings.domain_id = 2 AND domain_listings.listing_id = 12) LIMIT 1

domain_listings is a join table and id does not exist, the columns are domain_id and listing_id. As I mentioned, no problem with this in 2.1.2. Any guidance would be appreciated.

Reported by Patrick · February 1st, 2009 @ 02:24 AM

State: invalid
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Scott Taylor
    Scott Taylor

    Can you provide more information? What is the schema of those two tables? What AR call is triggering this query?

    February 1st, 2009 @ 05:13 AM

  2. Patrick
    Patrick

    This is the code from the form that is creating the sql

    <%= select_tag('domain_listings[domain_id][]', options_from_collection_for_select(Domain.find(:all), 'id', 'name', @listing.domains.collect {|d| d.id}), :multiple => true, :size => 5

    I've also attached part of my dev log file that shows the error. As I mentioned, the query worked up to 2.1.2 and then broke when I upgraded to 2.2.2. Thanks for the quick response...

    February 1st, 2009 @ 05:56 AM

  3. Patrick
    Patrick

    I attached some more schema information.

    February 1st, 2009 @ 06:39 PM

  4. Patrick
    Patrick

    Just wondered if anyone had a chance to look at this yet? right now I'm sticking to rails 2.1.2 until I at least have a work around. Maybe I need to find a way for it to write a different sql.

    February 14th, 2009 @ 07:14 PM

  5. siong1987
    siong1987

    Since the information that you provided is not really enough, you can try this:

    class DomainListing < ActiveRecord::Base belongs_to :listing belongs_to :domain, :foreign_key => 'domain_id' end

    February 15th, 2009 @ 02:35 AM

  6. Pratik
    Pratik
    • Assigned user changed from Frederick Cheung to Pratik
    • State changed from new to invalid

    You should try to submit a failing test case. http://guides.rails.info/contrib... might come handy!

    Thanks.

    March 8th, 2009 @ 01:26 PM