- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我正在构建一个应用程序,其中我有一个用 Rails 编写的后端和一个用 Vue 和 Amplify 编写的客户端。我的数据库是 MySQL,我使用 AWS AppSync 和 GraphQL 作为数据源(指向我的数据库)。
AWS Amplify 有一个框架,允许我使用一个简单的命令根据表名和列生成模式:amplify api add-graphql-datasource
.但是因为我使用的是 Rails 迁移,所以我的数据库使用的是 Rails 约定:带有蛇形列的复数表。
现在,问题在于 GraphQL 模式都很丑陋,并且没有使用正确的约定(类型和输入的单数名称,带有驼峰式的 props)。例子:
我的后端有以下迁移:
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.belongs_to :site, null: false
t.string :title
t.string :url
t.text :body
t.timestamps
end
end
end
type posts {
id: Int!
site_id: Int!
title: String
url: String
body: String
created_at: AWSDateTime!
updated_at: AWSDateTime!
}
type Query {
getPosts(id: Int!): posts
listPostss: [posts]
// ...
}
schema {
query: Query
// ...
}
input CreatepostsInput {
id: Int!
site_id: Int!
title: String
url: String
body: String
created_at: AWSDateTime!
updated_at: AWSDateTime!
}
最佳答案
我可以看到一些你可以做的事情:
表:
在您的迁移中,您可以更改表名,但现在您需要使用 self.table_name
让您的模型知道表名是什么。
# migration
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :post do |t| # singular 'post'
...
end
end
end
#model
class Post
self.table_name = "post" # i think you can also use a symbol :post
end
t.belongs_to
或
t.references
或
t.timestamps
。
# migration
class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :post do |t|
# do not use this below
# t.belongs_to :site, null: false
t.bigint :siteId, null: false
t.string :title
t.string :url
t.text :body
# do not use this below
# t.timestamps
t.datetime :createdAt, default: ->{'CURRENT_TIMESTAMP'}
t.datetime :updatedAt, default: ->{'CURRENT_TIMESTAMP'}
end
end
end
class Post
belongs_to :site, foreign_key: 'siteId'
end
created_at
、
updated_at
)不再是 ActiveRecord 所期望的列,因此您可能需要
override the ActiveRecord::Timestamp
module 才能让它们继续按预期工作。最简单的选择之一是使用以下内容更新您的
ApplicationRecord
或单个模型类:
class ApplicationRecord # or class Post
before_create :set_timestamps
before_save :set_timestamps
private
def set_timestamps
self.createdAt = DateTime.current if self.new_record?
self.updatedAt = DateTime.now
end
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
class << self
private
def timestamp_attributes_for_create
super << 'my_created_at_column'
end
def timestamp_attributes_for_update
super << 'my_updated_at_column'
end
end
end
Create<table>Input
,所以如果是这种情况,您可以将表命名为
Post
而不是
post
。
input CreatepostsInput {
}
关于ruby-on-rails - 如何覆盖关于复数表和蛇形列的 rails 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699571/
在 Snakemake 文档中, includes directive可以将另一个工作流程的所有规则合并到主工作流程中,并且显然可以显示在 snakemake --dag -n | dot -Tsvg
在 Snakemake 文档中, includes directive可以将另一个工作流程的所有规则合并到主工作流程中,并且显然可以显示在 snakemake --dag -n | dot -Tsvg
我们遵循将模型属性命名为 snake_case_variables 的 Laravel 标准。尽管 Laravel 只是我们系统中与 Javascript 前端和许多其他应用程序对话的 API 层。
当前情况:我想检测图像中的矩形(或正方形),这些矩形的轮廓并不完全一致。就像棋盘,外轮廓有整体。 可能的解决方案:我正在尝试实现主动轮廓算法,它应该可以帮助我检测物体的外部轮廓。我知道物体外面的一些点
我是一名优秀的程序员,十分优秀!