rails-activerecord

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

心不动则不痛 提交于 2020-12-29 12:13:45
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

南笙酒味 提交于 2020-12-29 12:12:27
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

佐手、 提交于 2020-12-29 12:09:13
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

狂风中的少年 提交于 2020-12-29 12:08:33
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

旧街凉风 提交于 2020-12-29 12:08:17
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

Rails Activerecord/Postgres time format

有些话、适合烂在心里 提交于 2020-08-27 05:56:39
问题 I am working on a Rails project using a Postgres database. For one of my models, I have a time column, called (cleverly) time. When I created the model, I set the data type for this column as 'time', with the (perhaps incorrect) understanding that this data type was for storing time only, no date. t.time :time However, when I submit data to the model, the time is correct but prefixed by an incorrect date: time: "2000-01-01 16:57:19" I just want the column to store the time (like '16:57:19').

Using Rails includes with conditions on children

ぐ巨炮叔叔 提交于 2020-08-07 05:00:07
问题 I have a model Parent that has many children Child . I want to get all Parent models and show every Child of the Parent as well. This is a classic use case for Rails' includes method, as far as I can tell. However, I can't get Rails to add conditions to the child models without limiting the Parent models to those that have children. For example, this only outputs parents that have children: Parent.includes(:children).where(children: {age: 10}).each do |parent| # output parent info parent