我有 2 个模型,注释和类别,每个类别有许多注释,而注释属于一个类别:
我如何检索具有各自类别颜色的所有笔记?到目前为止,我已经尝试了下图中的内容,但它返回“{”error”:“类别与注释不相关!”}”。
正如我在问题中提到的,我正在处理的当前 Laravel 6.0 项目有一些奇怪的数据库设置,其中模型(此处的 MainModel)MySQL 表已设置为AutoIncrementas NULL。并且客户端根本不允许更改表的定义。
我想在插入记录之前可靠地找到模型的下一个和上一个 ID(因为我无法从表中找到,因为 AutoIncrement 设置为 NULL),以便我可以输入相关记录(例如图像) )首先将主模型的 ID 正确插入到另一个表的参考 ID 字段中,将推荐/常见问题解答或任何所见即所得内容字段)插入到另一个参考表中。
目前我的主模型中有这个,但该next方法不能可靠地一致地返回精确的递增 ID:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Te7aHoudini\LaravelTrix\Traits\HasTrixRichText;
class [MainModel] extends Model
{
use HasTrixRichText;
protected $guarded = [];
public $timestamps = false;
protected $primaryKey = 'id';
protected $connection = '[connection1]';
protected $table = '[main_table]';
protected $fillable = ['id', '[titlefield]', '[wysiwyg_field]'];
/**
* Setup model event hooks
*/
public static function boot()
{
parent::boot();
self::creating(function ($model) { …Run Code Online (Sandbox Code Playgroud) 我有一个清单
val shoeCart = ShoeRepository.getShoeFromCart(this@ActivityCart)
Run Code Online (Sandbox Code Playgroud)
来自鞋库
fun getShoeFromCart(context: Context): List<ShoeModel> {
return getCart(context)
}
Run Code Online (Sandbox Code Playgroud)
ShoeModel 是一个数据类
data class ShoeModel
Run Code Online (Sandbox Code Playgroud)
我想知道我的 ShoesCart 中是否有重复的条目,如果有,有多少?
假设我有这个:
class Tree < ActiveRecord::Base
has_many :fruits
has_many :flowers
end
class Fruit < ActiveRecord::Base
belongs_to :tree
end
class Flower < ActiveRecord::Base
belongs_to :tree
end
Run Code Online (Sandbox Code Playgroud)
如何进行有效的查询来获取Tree至少具有一个Flower或Fruit实例或两者的所有实例?这个想法不是得到那些根本Tree没有的东西。FlowerFruit
当我运行 NER 模型时,我得到:
UserWarning: [W031] Model 'en_model' (0.0.0) requires spaCy v2.2 and is incompatible with the current spaCy version (2.3.2)
Run Code Online (Sandbox Code Playgroud)
请告知我该如何修复它?
Python 3.7.9、spaCy 2.3.2、Ubuntu 18.04。
我正在尝试使用sequelize 创建一个模型,然后添加,然后使用sync({force: true }) 如此处所示,使MySQL 创建表(如果不存在)。然而,它对我大喊大叫,说我的 MySQL 查询有错误(应该是由 Sequelize 生成的)。这是模型:
// admin.model.js
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = require('../db/connection');
const validator = require("validator")
const Admin = sequelize.define('Admin', {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate(value) {
if (!validator.isEmail(value)) {
throw new Error('Invalid email');
}
},
},
password: {
type: DataTypes.STRING,
allowNull: false,
validate(value) {
if (!value.match(/\d/) || !value.match(/[a-zA-Z]/)) {
throw new Error('Password must contain at least one letter and one number');
} …Run Code Online (Sandbox Code Playgroud) 想象一下你有一个控制器或一些代码,看起来像这样:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class TeamController {
public function create(Request $request): JsonResponse
{
$request->validated();
$team = new Team(['name' => $request->get('name')]);
if (!$team->save()) {
// some really important logic you want to cover
// cover by a test.
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
您无法轻松地模拟 Eloquent 模型而不感到有点混乱,请参阅我关于如何从save()调用返回false 的答案。
我将从我的模型开始:
class Project < ApplicationRecord
has_many :permissions
has_many :wallets, through: :permissions
has_many :follows
has_many :wallets, through: :follows
end
class Permission < ApplicationRecord
belongs_to :project
belongs_to :wallet
end
class Follow < ApplicationRecord
belongs_to :project
belongs_to :wallet
end
class Wallet < ApplicationRecord
has_many :permissions
has_many :projects, through: :permissions
has_many :follows
has_many :projects, through: :follows
end
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,权限和关注都是通过项目和钱包的关联来实现的。
它们有不同的用途(权限允许钱包访问管理项目,而关注让钱包“关注”项目以进行更新)。
那么我该如何区分它们呢?例如,如果我这样做Wallet.find(1).projects,它默认使用“Follow”模型......尽管在某些情况下我希望它实际上使用“Permission”模型。
我有这个冻结的部分
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'user_model.freezed.dart';
part 'user_model.g.dart';
@freezed
class UserModel with _$UserModel {
factory UserModel({
required String id,
@Default('') String uniqueId,
@Default(DateTime.now()) DateTime dob,
}) = _UserModel;
factory UserModel.fromJson(Map<String, dynamic> json) =>
_$UserModelFromJson(json);
}
Run Code Online (Sandbox Code Playgroud)
但由于DateTime.now() ,我无法生成所需的文件。
如果我做这样的事情:
factory UserModel({
required String id,
@Default('') String uniqueId,
required DateTime dob,
}) = _UserModel;
Run Code Online (Sandbox Code Playgroud)
它会起作用,但我必须手动将生成的数据编辑为:
dob: (json['dob'] as Timestamp?)?.toDate() ?? DateTime.now()
Run Code Online (Sandbox Code Playgroud)
从
dob: DateTime.parse(json['dob'] as String),
Run Code Online (Sandbox Code Playgroud)
我不能一直手动编辑它。
请问如何生成包括日期时间的模型类。
我在 nuxt 3 项目中使用 Typescript,当我从组件导入 Typescript 模型时收到此错误。
The requested module '/_nuxt/models/component/blog/BlogPage.interface.ts' does not provide an export named 'default'
Run Code Online (Sandbox Code Playgroud)
这是我的组件。组件渲染器.vue
<script setup lang="ts">
import BlogPage from "~~/models/component/blog/BlogPage.interface";
import HomePage from "~~/models/component/home/HomePage.interface";
import ProductPage from "~~/models/component/product/ProductPage.interface";
const props = defineProps<{
page: HomePage | ProductPage | BlogPage;
}>();
console.log(typeof props.page);
</script>
Run Code Online (Sandbox Code Playgroud)
这是进口型号。BlogPage.interface.ts
interface BlogPage {
data: any;
}
export default BlogPage;
Run Code Online (Sandbox Code Playgroud)
最后这是我的nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
alias: {
'models': './models/*',
},
typescript: {
strict: true,
},
css: ["~/assets/css/main.css"],
modules: …Run Code Online (Sandbox Code Playgroud) model ×10
associations ×2
laravel ×2
mysql ×2
sequelize.js ×2
typescript ×2
dart ×1
data-class ×1
eloquent ×1
flutter ×1
import ×1
increment ×1
kotlin ×1
laravel-6 ×1
list ×1
mutablelist ×1
node.js ×1
nuxtjs3 ×1
python-3.x ×1
spacy ×1
testing ×1
types ×1