Code Monkey home page Code Monkey logo

Comments (10)

Mirv avatar Mirv commented on September 28, 2024

Note, I found that :delete was being used, doing so is not rails way...as it prevents other related callbacks from firing, meaning there's potentially checks that aren't ran when this happens. :destroy is considered a safer option.

from pdb.

Mirv avatar Mirv commented on September 28, 2024

inserted

, dependent: :destroy

To players, entities & users to honor the foreign keys.

EntitiesControllerTest: test_should_destroy_entity
--------------------------------------------------
  Entity Load (1.2ms)  SELECT  "entities".* FROM "entities" WHERE "entities"."id" = 1 LIMIT 1
  User Load (1.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = 135138680 LIMIT 1
   (1.0ms)  SELECT COUNT(*) FROM "entities"
Processing by EntitiesController#destroy as HTML
  Parameters: {"id"=>"1"}
  User Load (1.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = 135138680  ORDER BY "users"."id" ASC LIMIT 1
  Entity Load (1.3ms)  SELECT  "entities".* FROM "entities" WHERE "entities"."id" = 1 LIMIT 1
  Savepoint (0.7ms)  SAVEPOINT active_record_1
  Player Load (8.6ms)  SELECT  "players".* FROM "players" WHERE "players"."entity_id" = 1 LIMIT 1
  User Load (14.3ms)  SELECT  "users".* FROM "users" WHERE "users"."player_id" = 1 LIMIT 1
  SQL (15.9ms)  DELETE FROM "users" WHERE "users"."id" = 135138680
  Savepoint (17.0ms)  ROLLBACK TO SAVEPOINT active_record_1
Completed 500 Internal Server Error in 2752ms (ActiveRecord: 59.4ms)

Resulting error summary...

Finished in 11.005418s, 0.6361 runs/s, 0.9086 assertions/s.

  1) Error:
EntitiesControllerTest#test_should_destroy_entity:
Java::JavaLang::StackOverflowError: 
   
7 runs, 10 assertions, 0 failures, 1 errors, 0 skips

from pdb.

Mirv avatar Mirv commented on September 28, 2024

There's a small part of me that believes you are going to have more than one entity on the map/game belonging to a single player & that means you need to have a has_many relationship or a has_many: :through relationship.

from pdb.

Mirv avatar Mirv commented on September 28, 2024

Also, why does the entity HAVE a player? Why doesn't the player HAVE an entity on the map?

from pdb.

Mirv avatar Mirv commented on September 28, 2024

add_foreign_key :identities, :users, on_delete: :cascade

https://stackoverflow.com/questions/29544693/cant-delete-object-due-to-foreign-key-constraint

On this recommendation, I'm branching again & going to try to remove then add with the on_delete: :cascade ...

from pdb.

Mirv avatar Mirv commented on September 28, 2024

Oddity:

I noticed there's duplicates in the schema.rb on two of the foreign key entries as i'm doing this...that might have been the issue too...

  add_foreign_key "entities", "map_points", name: "entities_map_point_id_fk"
  add_foreign_key "entities", "map_points", name: "entities_map_point_id_fk"
  add_foreign_key "players", "entities", name: "players_entity_id_fk"
  add_foreign_key "players", "entities", name: "players_entity_id_fk"
  add_foreign_key "users", "players", name: "users_player_id_fk"

from pdb.

Mirv avatar Mirv commented on September 28, 2024

duplication watch on rails....not catching these in duplicate? should rails sort that or should I code dive it to suggest a fix to rails team?

from pdb.

Mirv avatar Mirv commented on September 28, 2024

Out put from removing the foreign keys...

   (43.4ms)  SELECT version()
  ActiveRecord::SchemaMigration Load (1.8ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to FixForeignKey (20171017222022)
== 20171017222022 FixForeignKey: migrating ====================================
-- remove_foreign_key("users", "players")
   (3.7ms)  ALTER TABLE "users" DROP CONSTRAINT "users_player_id_fk"
   -> 0.0099s
   -> 0 rows
-- remove_foreign_key("players", "entities")
   (1.1ms)  ALTER TABLE "players" DROP CONSTRAINT "players_entity_id_fk"
   -> 0.0036s
   -> 0 rows
-- remove_foreign_key("entities", "map_points")
   (2.2ms)  ALTER TABLE "entities" DROP CONSTRAINT "entities_map_point_id_fk"
   -> 0.0335s
   -> 0 rows
== 20171017222022 FixForeignKey: migrated (0.0511s) ===========================

  SQL (4.3ms)  INSERT INTO "schema_migrations" ("version") VALUES ('20171017222022')
  ActiveRecord::SchemaMigration Load (0.9ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (33.5ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'entities'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (85.1ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'identities'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (7.6ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'map_points'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (5.0ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'players'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (5.4ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'terrains'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (3.3ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'users'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (2.9ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'entities'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (3.0ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'identities'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (3.2ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'map_points'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (2.9ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'players'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (3.4ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'terrains'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 
   (3.1ms)  SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_class t2 ON c.confrelid = t2.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid JOIN pg_namespace t3 ON c.connamespace = t3.oid WHERE c.contype = 'f'   AND t1.relname = 'users'   AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname 

from pdb.

Mirv avatar Mirv commented on September 28, 2024

The stackoverflow error.... It's a bug in the interpreter, but often caused by adverse circumstances that would kill the program anyhow. You're supposed to always get a nice Ruby stack trace. If you get a segfault instead, it's a bug.

from pdb.

marcandregirard avatar marcandregirard commented on September 28, 2024

Since I moved away from Ruby and Rails, I'll be closing this issue since it's not relevant anymore.

from pdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.