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.

default_scope for select option builds invalid SQL.

#2626

This query failed in my app due to the fact that you can't declare multiple columns in the "SELECT count" fragment:

SELECT count(id,title) AS count_id_title FROM resources INNER JOIN resources_tags ON resources.id = resources_tags.resource_id WHERE (((resources.approved = 1) AND (resources_tags.tag_id = 109 )) AND (resources_tags.tag_id = 109 )) )

The query was invoked by "m = Model.approved" in the controller and then calling "m.size" in the view.

This is declared in the model: default_scope :select => 'id,title' named_scope :approved, :conditions => { :approved => true }

Rails 2.3.2 MySQL 5.0 Win XP

Reported by bill · May 8th, 2009 @ 09:44 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Emili Parreño
    Emili Parreño
    • Tag set to activerecord, count, mysql, patch

    Is an error in construct_count_options_from_args(*args) method when build the sql sentence

    Fix for this bug in the pacth file

    May 13th, 2009 @ 10:41 AM

  2. Pratik
    Pratik

    Hi Emili,

    The patch needs failing tests.

    Thanks!

    May 21st, 2009 @ 09:34 AM

  3. Emili Parreño
    Emili Parreño

    I attach the patch with tests

    May 21st, 2009 @ 11:30 AM

  4. Emili Parreño
    Emili Parreño

    What about this patch? I sent the patch with tests.

    June 26th, 2009 @ 09:13 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  6. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:18 AM