Comments (10)
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.
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.
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.
Also, why does the entity HAVE a player? Why doesn't the player HAVE an entity on the map?
from pdb.
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.
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.
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.
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.
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.
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)
- How are we managing resources HOT 2
- Error when sign in HOT 1
- Add creation of account with mail and password HOT 4
- Use of bcrypt or alternative for hasing pwd? HOT 3
- Post login, help button -> omni auth facebook HOT 1
- EntitiesControllerTest#test_should_destroy_entity HOT 4
- Change the way Terrain define the backgournd color HOT 1
- Update the versions of the project HOT 1
- CSS file not loading for the site. HOT 1
- Add check for uniqueness of User for Player
- Lazy loading not working for currentZone in Player HOT 1
- Various small improvement HOT 1
- Dockerize the application HOT 2
- Dev instance HOT 2
- Local file to override properties for the server HOT 1
- Seed data HOT 1
- Add login and account creation
- Finish re-creating logic from the original implementation
- Setup seeding of database
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdb.