datamapper/dm-core — Issue #169: custom default_scope and broken order statement on postgres
Author: solnic
Created: 2011-12-09 09:46:23+00:00
State: open

Looks like we have a regression:

``` ruby
require "rubygems"

require 'dm-core'
require 'dm-migrations'

class ClipCollection
include DataMapper::Resource
property :id, Serial, :key => true
has n, :clips, :through => Resource
end

class Clip
include DataMapper::Resource
property :id, Serial, :key => true
property :title, Text
has n, :tagruns
has n, :clip_collections, :through => Resource
default_scope.update(:order => [:title.asc])
end

class Tagrun
include DataMapper::Resource
property :id, Serial, :key => true
belongs_to :clip, :required => true
end

DataMapper.finalize
DataMapper.setup(:default, 'postgres://datamapper@localhost/datamapper_default_tests')
DataMapper.auto_upgrade!

@clip_collection = ClipCollection.create
ClipClipCollection.create :clip_collection => @clip_collection, :clip => Clip.create

@clip_collection.clips.each do |current_clip|
Tagrun.create(:clip => current_clip)
end
```

output:

```
ERROR: column "clips.title" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...collection_id" = 6 GROUP BY "clips"."id" ORDER BY "clips"."t...
```

It's broken since DM 1.1.0, works fine on DM 1.0.2