#1086 ✓resolved
ojak

Using Constraints + Remixables fails.

Reported by ojak | October 8th, 2009 @ 02:22 AM | in 1.0.0

Constraints and Remixables no longer play nice together (worked in dm-0.10.0 "next" branch in September). It looks like this problem occurs when using Remixables.

Below are steps to reproduce the errors (using do_mysql-0.10.0 [gem], merb-1.1 [source], dm-0.10.1 [gem]).

Steps to reproduce:


Works

# This simple example WORKS
class Good
  include DataMapper::Resource
  property :id, Serial
  has n, :bads
end

class Bad
  include DataMapper::Resource
  property :id, Serial
  belongs_to :good
end
$ rake db:migrate

The above example creates the tables as expected.


Fails

# This example with remixables FAILS.
class Good
  include DataMapper::Resource
  property :id, Serial
  has n, :bads
  remix 0..1, :addressables, :as => "address"
end

class Bad
  include DataMapper::Resource
  property :id, Serial
  belongs_to :good
end

module Addressable
  include DataMapper::Resource
  is :remixable,
    :as     => 'address',   # Accessor set to Model#address
    :suffix => 'address'    # Default suffix is module name pluralized
  
  property :id,          Serial
  property :address,     String
end
$ rake db:migrate
   ...
   ...
   ~ (0.004498) ALTER TABLE `bads` ADD CONSTRAINT `bads_good_fk` FOREIGN KEY (`good_id`) REFERENCES `goods` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
   ~ (0.001559) SELECT COUNT(*) FROM "information_schema"."table_constraints" WHERE "constraint_type" = 'FOREIGN KEY' AND "table_schema" = 'test_merb' AND "table_name" = 'good_addresses' AND "constraint_name" = 'good_addresses_good_fk'
   ~ Can't create table './test_merb/#sql-8d_28.frm' (errno: 150) (code: 1005, sql state: HY000, query: ALTER TABLE `good_addresses` ADD CONSTRAINT `good_addresses_good_fk` FOREIGN KEY (`good_id`) REFERENCES `goods` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, uri: mysql://root@localhosttest_merb?socket=/tmp/mysql.sock)
   rake aborted!
   Can't create table './test_merb/#sql-8d_28.frm' (errno: 150)

The above examples with remixables fails to create the constraints.

Comments and changes to this ticket

  • ojak
  • ojak

    ojak October 8th, 2009 @ 01:15 PM

    See attached file for example.

    Tested on:
    dm-core 0.10.1 mysql 5.0.83 ruby 1.8.7p174

  • ojak

    ojak October 8th, 2009 @ 01:18 PM

    Output of attached example:

    $ ruby dm-remixables-test.rb 
     ~ Generating Remixed Model: PostAddress
     ~ (0.000105) SET sql_auto_is_null = 0
     ~ (0.000076) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
     ~ (0.000311) SHOW TABLES LIKE 'addressables'
     ~ (0.000230) SHOW TABLES LIKE 'posts'
     ~ (0.000191) SHOW TABLES LIKE 'post_addresses'
     ~ (0.000192) SHOW TABLES LIKE 'comments'
     ~ Skipping auto_migrate_down! for remixable module (Addressable)
     ~ (0.000157) DROP TABLE IF EXISTS posts
     ~ (0.000105) DROP TABLE IF EXISTS post_addresses
     ~ (0.000109) DROP TABLE IF EXISTS comments
     ~ Skipping auto_migrate_up! for remixable module (Addressable)
     ~ (0.000268) SHOW TABLES LIKE 'posts'
     ~ (0.000166) SHOW VARIABLES LIKE 'character_set_connection'
     ~ (0.000550) SHOW VARIABLES LIKE 'collation_connection'
     ~ (0.003049) CREATE TABLE posts (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, body TEXT, PRIMARY KEY(id)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
     ~ (0.000336) SHOW TABLES LIKE 'post_addresses'
     ~ (0.001830) CREATE TABLE post_addresses (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, address VARCHAR(50), post_id INTEGER NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
     ~ (0.000306) SHOW TABLES LIKE 'comments'
     ~ (0.001594) CREATE TABLE comments (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, body TEXT, post_id INT(10) UNSIGNED NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
     ~ (0.011253) CREATE INDEX index_comments_post ON comments (post_id)
     ~ (0.003566) SELECT COUNT(*) FROM "information_schema"."table_constraints" WHERE "constraint_type" = 'FOREIGN KEY' AND "table_schema" = 'test_dm_remixables' AND "table_name" = 'post_addresses' AND "constraint_name" = 'post_addresses_post_fk'
     ~ Can't create table './test_dm_remixables/#sql-8d_5d.frm' (errno: 150) (code: 1005, sql state: HY000, query: ALTER TABLE post_addresses ADD CONSTRAINT post_addresses_post_fk FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE NO ACTION ON UPDATE NO ACTION, uri: mysql://root:@127.0.0.1test_dm_remixables?encoding=UTF-8)
    /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/adapters/data_objects_adapter.rb:162:in execute_non_query': Can't create table './test_dm_remixables/#sql-8d_5d.frm' (errno: 150) (DataObjects::SQLError)
    
    
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/adapters/data_objects_adapter.rb:162:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/adapters/data_objects_adapter.rb:266:in `with_connection'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/adapters/data_objects_adapter.rb:160:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:86:in `create_relationship_constraint'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:268:in `send'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:268:in `execute_each_relationship'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:267:in `each_value'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:267:in `execute_each_relationship'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:258:in `auto_migrate_up_with_constraints!'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/migrations.rb:49:in `send'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/migrations.rb:49:in `repository_execute'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/model/descendant_set.rb:33:in `each'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/model/descendant_set.rb:33:in `each'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/migrations.rb:48:in `repository_execute'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-constraints-0.10.1/lib/dm-constraints/migrations.rb:23:in `auto_migrate_up!'
        from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/migrations.rb:22:in `auto_migrate!'
        from dm-remixables-test.rb:55</code>
    
    
    
    
  • ojak

    ojak October 11th, 2009 @ 06:49 PM

    Here's a patch that checks whether the fk ID is Serial then adjusts the column type accordingly.

  • ojak

    ojak October 11th, 2009 @ 06:49 PM

    • Assigned user changed from “Martin Gamsjaeger (snusnu)” to “Dan Kubb (dkubb)”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 2nd, 2010 @ 12:41 PM

    • State changed from “new” to “unconfirmed”
    • Assigned user cleared.

    @ojak: Could you provide a failing spec with this patch? I will apply it once there is a spec that reproduces the failure.

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) March 25th, 2010 @ 09:24 AM

    • Tag set to dm-is-remixable
    • Assigned user set to “Martin Gamsjaeger (snusnu)”
  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) March 30th, 2010 @ 06:40 PM

    • Milestone set to 1.0.0
    • State changed from “unconfirmed” to “resolved”

    I believe this is fixed on current master stuff. I think it was due to an explicit property declaration that didn't have the :min => 1 option specified and thus didn't match the foreign key types generated by #has. I've removed the last explicit property declaration from dm-is-remixable in

    http://github.com/datamapper/dm-more/commit/4d0528ffcec0099a1e54f14...

    and I'm marking this as resolved for now (I think it was fixed before that commit already). Feel free to reopen the ticket if this is still a problem.

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 »

Pages