views:

56

answers:

1

I'm just begining to use DataMappers associations, just to test things out have a very simple table structure, and it's is borking.

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

DataMapper.setup( :default, "sqlite3://#{Dir.pwd}/dbtest.db" )

    class Account
      include DataMapper::Resource
      property :id, Serial
      has 1, :userprofile, :model =>"UserProfile"
    end  

    class UserProfile
        include DataMapper::Resource
        property :id, Serial
        belongs_to :Account
    end
DataMapper.finalize #whether I have this before or after auto migrate the result is the same
DataMapper.auto_migrate!

This should just work, nice and simple, DM is working for everything else(I'e already been using it plenty).

Here is the result when I run this code, anyone know what the problem is?:

DataObjects::SyntaxError: duplicate column name: account_id (code: 1, sql state: , query: CREATE TABLE "user_profiles" ("id" INTEGER NOT NULL PRIMARY
KEY AUTOINCREMENT, "account_id" INTEGER NOT NULL, "account_id" INTEGER NOT NULL), uri: sqlite3://d/Borrow/dbtest.db)
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:92:in `execute_non_query'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:92:in `create_model_storage'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:90:in `each'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:90:in `create_model_storage'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-do-adapter-1.0.0/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:85:in `create_model_storage'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:79:in `create_model_storage'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:175:in `auto_migrate_up!'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:130:in `auto_migrate!'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:45:in `send'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:45:in `repository_execute'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/model/descendant_set.rb:33:in `each'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/model/descendant_set.rb:33:in `each'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:44:in `repository_execute'
        from d:/Ruby/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:22:in `auto_migrate!'
A: 

In UserProfile, try specifying a lowercase :account, like so:

  belongs_to :account

Also, if you follow the convention by adding an underscore in the :user_profile relationship in Account,

  has 1, :user_profile

you can remove the :model key.

Ripta Pasay