#1507 new
KRM

PostgreSQL broken query in belongs_to / has 1:N

Reported by KRM | April 26th, 2011 @ 08:45 PM

Ruby 1.9.2-p180, DM 1.1.0

Models:
class Resource
include DataMapper::Resource storage_names[:default] = 'resource' property :resource_id, Serial property :parent_id, Integer property :manufacturer_id,Integer property :component, String property :name, String property :status, String property :updated, String

has n, :resource_usage belongs_to :manufacturer end

class Manufacturer
include DataMapper::Resource storage_names[:default] = 'manufacturer' property :manufacturer_id, Serial property :name, String

has n, :resource end

ruby-1.9.2-p180 :002 > r = Resource.get(8595)
DataObjects::SyntaxError: ERROR: column "manufacturer_manufacturer_id" � (code: 50360452, sql state: 42703, query: SELECT "resource_id", "parent_id", "manufacturer_id", "component", "name", "status", "updated", "manufacturer_manufacturer_id" FROM "resource" WHERE "resource_id" = 8595 LIMIT 1, uri:

It seems that when trying to use belongs_to and has 1/n, the related key is being corrupted by appending "tablename_" to the columns and breaking the query. If it is a configuration issue, it is not clear on the DataMapper documentation site. We are using PostgreSQL 8.4 and we have seen similar issue from both Windows, Linux and FreeBSD development environments.

Comments and changes to this ticket

  • KRM

    KRM April 26th, 2011 @ 08:49 PM

    better formatting:

    require 'rubygems'
    require 'data_mapper'
    
    DataMapper::Logger.new('log/dm.log', :debug)
    
    DataMapper.setup(:default, {
      :adapter => 'postgres',
      :database => 'XX',   :username => 'XX',
      :password => 'XX',   :host => 'XX',   :port => 5432
    })
    
    class Resource
      include DataMapper::Resource
      storage_names[:default] = 'resource'
      property :resource_id,    Serial
      property :parent_id,      Integer
      property :manufacturer_id,Integer
      property :component,      String
      property :name,           String
      property :status,         String
      property :updated,        String
    
      has 1, :resource_property
      has n, :resource_usage
      belongs_to :manufacturer
    end
    
    class Manufacturer
      include DataMapper::Resource
      storage_names[:default] = 'manufacturer'
      property :manufacturer_id, Serial
      property :name,     String
    
      has n, :resource
    end
    
    .
    .
    .
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages