model 相关问题

作为MVC模式的一部分,Model管理应用程序的行为和数据。

如何确定 Laravel 4.2 中模型是否使用软删除

如何确定 Laravel 中的模型是否使用软删除? 在 Laravel API 中,我发现了函数 isSoftDeleting(),但显然该函数已从 Laravel 4.2 中删除,因为它使用了

回答 6 投票 0

Rails 连接不再工作 - 以前工作过

情况 我有一张模型发票,其属性为 freezen,用于在我的应用程序中处理存档。归档后,应该生成并附加 PDF(我的应用程序中名为

回答 1 投票 0

Laravel:在Where条件中使用追加字段

我是 Laravel 的新手。 我有一个模型会员,其中包含“出生日期”字段和一个名为“类别”的附加字段(它包含取决于年龄的运动类别信息,例如(10 岁以下、15 岁以下、6 月...

回答 1 投票 0

从控制器发送到视图时模型为空

我认为模型出现 System.NullReferenceException: @页 @型号列表 @{ 字符串 sHtml = TestPageView.GetHtml(Model); // <-- 我认为 System.NullReferenceException 会得到 Model: @page @model List<MyApp.Models.Student> <div> @{ string sHtml = TestPageView.GetHtml(Model); // <-- NullReferenceException here } @Html.Raw(sHtml) </div> 这是我的控制器操作: public IActionResult TestPage() { return View(SomeStudents.Students); } 这是我的Student模型: namespace Models { public class Student { public int Id; public string Name; public int Age; public int Grade; } } ...列表来自这里: namespace Data { public class SomeStudents { public static List<Student> Students { get; } = new List<Student>() { new Student() { Id = 1, Name = "Adam", Age = 20, Grade = 69 }, new Student() { Id = 2, Name = "Mark", Age = 21, Grade = 80 }, new Student() { Id = 3, Name = "Bill", Age = 18, Grade = 51 } }; } } 我回顾了几个报告相同问题的稍微相似的问答,包括: 模型未从控制器传递到视图 检索从控制器发送的视图中的数据 ...但我没有找到任何可以解决我的确切场景的内容(我认为这非常简单,一点也不复杂,这是令人困惑的)。 我尝试显式命名视图,如这个答案: public IActionResult TestPage() { return View("TestPage", SomeStudents.Students); } 我还尝试稍微调整视图,使用此示例中稍微修改的摘录: @page @model List<MyApp.Models.Student> <div> @foreach (var item in Model) { // <-- NullReferenceException here @Html.DisplayFor(modelItem => item.Name) } </div> 但是,在所有情况下,尝试在视图中访问 Model 都会导致相同的 NullReferenceException。 如何将 Student 列表传递到我的视图? 解决方案是删除 @page 指令。 该指令适用于 Razor 页面,而不是 MVC 视图。

回答 1 投票 0

带有tortoise-orm模型的fastapi早期初始化模型仍然没有找到

我是 api 开发的新手,我正在尝试将 tortoise-orm 与 fastapi 一起使用,但 forlder 结构略有不同(对于用户模型,例如 src-> models->user.py): 项目结构 还有...

回答 1 投票 0

传递整个模型还是仅传递标识符更好?

我经常发现自己将(数据)模型传递到我需要的地方,作为方法参数沿层次结构向下传递,作为事件参数沿层次结构向上传递。 一个说明性的例子是我...

回答 2 投票 0

如何保存序列分类模型分词器和配置的微调 bert?

我想将微调后的所有训练模型保存在文件夹中: 配置.json 添加的_token.json Special_tokens_map.json tokenizer_config.json 词汇表.txt pytorch_model.bin 我只能救

回答 1 投票 0

如何将 TargetLink 模型转换为 Simulink

我是 Targetlink 新手,需要将 Targetlink 块转换为 simulink 块。我还需要 Targetlink 许可证才能进行转换吗?

回答 3 投票 0

更新 Django 中的 OneToOneField 关系

我想在我的程序中以编程方式更新 Django 中用户模型的 exera 字段。 我如何更新 Django 中用户模型的额外字段? def user_profile(请求): query_set = str(组。

回答 1 投票 0

如何在Rails中对没有控制器的多个模型使用form_with

我正在尝试创建用户可以使用的食谱应用程序。该应用程序的一部分是管理员用户可以创建食谱和说明。 有一个包含所有用户的用户模型/表。这有一个

回答 1 投票 0

Web API C# 模型

如何创建一个在 API POST 中接受此内容的模型? { “formId”:“ff2f0a7f-aa26-11ee-bc5f-0242ac110009”, "工作流程ID": "", “状态”...

回答 1 投票 0

Codeigniter 模型扩展了 CI_MODEL

我想在 core 文件夹中创建 2 个不同的模型扩展 CI_Model, 例如: 类 MY_FirsModel 扩展 CI_Model { } 类 MY_SecondModel 扩展 CI_Model { } 使用时可以吗

回答 2 投票 0

另一个模型中的模型列表仅保存列表中所有项目中最后添加的项目

对于 (int x=0; x for (int x=0; x<listaEquipes.length; x++) { await _loadEquipe(listaEquipes[x].id.toString()); TabelaListaEquipes _reg = TabelaListaEquipes(); _reg.equipeId = listaEquipes[x].id.toString(); _reg.equipe = listaAtletaEquipe; //print (_reg.equipe![0].nome.toString()); listaEquipesGeral.add(_reg); } 此型号: class TabelaListaEquipes { String? equipeId; List<TabelaInscricoes>? equipe; TabelaListaEquipes( { this.equipeId, this.equipe}); } 现在我看到最后一个reg保存在列表的所有iten中,为什么? 这就对了: listaEquipesGeral[0].equipe == listEquipesGeral[1].equipe ...仍然添加了最后一项。为什么?? _loadEquipe 函数,它也有效,我已经测试过了, List<TabelaInscricoes> listaAtletaEquipe = []; Future<void> _loadEquipe(equipId) async { setState(() { listaAtletaEquipe.clear(); carregandoEquipe = true; }); TabelaInscricoes _result = TabelaInscricoes(); CollectionReference _dbCollection = FirebaseFirestore.instance.collection('campeonatos').doc(resultSelect.campId).collection('divisoes').doc(resultSelect.divId).collection('equipes').doc(equipId).collection('atletas'); await _dbCollection.orderBy('pos2', descending: false).get().then((QuerySnapshot querySnapshot) async { if (querySnapshot.docs.isNotEmpty) { querySnapshot.docs.forEach((element) async { _result = TabelaInscricoes.fromJson(element.data()! as Map<String, dynamic>); if (_result.campId == resultSelect.campId && _result.divId == resultSelect.divId) { _result.id = element.id; _result.filePath = ""; setState(() { listaAtletaEquipe.add(_result); }); } }); for (int x = 0; x<listaAtletaEquipe.length; x++) { for (int y = 0; y<listaAtletas.length; y++) { if (listaAtletaEquipe[x].atletaId.toString() == listaAtletas[y].id.toString()) { setState(() { listaAtletaEquipe[x].nome = listaAtletas[y].nome; listaAtletaEquipe[x].fotoNome = listaAtletas[y].fotoNome; listaAtletaEquipe[x].filePath = listaAtletas[y].filePath; listaAtletaEquipe[x].dataN = listaAtletas[y].dataN; listaAtletaEquipe[x].fone1 = listaAtletas[y].fone1; listaAtletaEquipe[x].fone2 = listaAtletas[y].fone2; listaAtletaEquipe[x].nTitulo = listaAtletas[y].nTitulo; listaAtletaEquipe[x].info = listaAtletas[y].info; listaAtletaEquipe[x].email = listaAtletas[y].email; }); } } } for (int x=0; x<listaAtletaEquipe.length; x++) { if (listaAtletaEquipe[x].fotoNome.toString().isNotEmpty) { await MyStorage.getUrl(context, "atletas/${listaAtletaEquipe[x].fotoNome.toString()}").then((value) { setState(() { listaAtletaEquipe[x].filePath = value; }); }); } } setState(() { carregandoEquipe = false; }); }else { setState(() { carregandoEquipe = false; }); } }); } AtletaEquipes 型号操作系统列表: class TabelaInscricoes{ bool? carregando = true; String? id; String? campId; String? divId; String? atletaId; String? nome_responsavel; String ?posicao; String? filePath; Uint8List? imageFile; String? usuario; String? nInscricao; String? nome; String? dataN; String? nTitulo; String? fone1; String? fone2; String? info; String? email; String? fotoNome; String? pos2; String? selected; TabelaInscricoes({ this.carregando, this.nome, this.dataN, this.nTitulo, this.fone1, this.fone2, this.info, this.email, this.id, this.campId, this.divId, this.posicao, this.nome_responsavel, this.nInscricao, this.atletaId, this.selected, this.pos2, this.fotoNome, this.filePath, this.imageFile, this.usuario}); Map<String, dynamic> toJson() => { 'campId': campId, 'divId': divId, 'atletaId': atletaId, 'nome_responsavel': nome_responsavel, 'posicao': posicao, 'usuario': usuario, 'nInscricao': nInscricao, 'pos2': pos2, 'selected': selected }; TabelaInscricoes.fromJson(Map<String, dynamic> json) : campId = json['campId'], divId = json['divId'], atletaId = json['atletaId'], nome_responsavel = json['nome_responsavel'], posicao = json['posicao'], nInscricao = json['nInscricao'], pos2 = json['pos2'], selected = json['selected'], usuario = json['usuario']; } 这里发生了什么,listaEquipesGeral 总是保存最后添加的所有项目。 我明白了,解决方案是在模型内的列表中逐项添加: for (int x=0; x<listaEquipes.length; x++) { await _loadEquipe(listaEquipes[x].id.toString()); TabelaListaEquipes _reg = TabelaListaEquipes(); _reg.equipeId = listaEquipes[x].id.toString(); _reg.equipe = []; //here above the solution, include for to put item by item, and it works for (int y = 0; y<listaAtletaEquipe.length; y++) { _reg.equipe!.add(listaAtletaEquipe[y]); } //print (_reg.equipe![0].nome.toString()); listaEquipesGeral.add(_reg); }

回答 1 投票 0

Laravel 动态扩展或使用 Traits

可以在运行时扩展或使用不同的类吗? 例子: 假设我们有一个名为 Player 的模型(我们的 A 模型) 可以在运行时扩展或使用不同的类吗? 示例: 假设我们有一个 model 称为 Player(我们的 A 模型) <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Player extends Model{ } 我们还有另外 2 个型号(B 和 C 型号) <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; protected $connection= 'db_b'; class PlayerInfoB extends Model{ function getName(){ return $this->name; } } 我们的C型号 <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; protected $connection= 'db_c'; class PlayerInfoC extends Model{ function getName(){ return $this->name_g; } } 模型A (Player)如何在运行时根据配置或其他数据扩展Model B or C 为什么我需要这个。 我有 2 个或更多不同的表,这些表的列有不同的名称,例如: Table 1 - name Table 2 - name_g Table 3 - name_full 所以我需要一个可以随时调用的包装器getName(),而无需检查现在使用的表。 $player = Player::get(); echo $player->getName(); 如果有不清楚的地方,请评论,我会更新我的问题。 更新基于madalin-ivascu答案可以这样完成吗? class Player extends Model{ protected $model; public function __construct(){ $this->setModel(); parent::__construct(); } protected function setModel(){ $this->model = $this->column_model_name } function getAttributeName(){ return $this->model->getName(); } } 如果不使用 eval 或 dirty hacks,就不可能在运行时编写一个类。您必须重新考虑您的类设计,因为您不太可能需要通过良好的设计来做到这一点。 您可以做的是使用方法 setTable 和 on: 在运行时更改模型实例上的表和数据库连接 Player::on('db_b')->setTable('player_info_b')->find($id); 另一种方法(首选)是定义模型 PlayerInfoC 和 PlayerInfoB 来扩展您的 Player 模型,然后根据您的情况在需要时实例化类 B 或 C。 在您的代码中,您的脚本必须具有您检查的状态,以便知道何时使用正确的模型? 既然如此,为什么不在 get name 中使用参数呢? class Player extends Model{ function getName($field){ return isset($this->{$field}) ? $this->{$field} : null; } } 如果你经常这样做,那么使用魔法方法: class Player extends Model{ function __get($key){ return isset($this->{$field}) ? $this->{$field} : null; } } ... echo $myModelInstance->{$field}; http://php.net/manual/en/language.oop5.overloading.php#object.get 在 Laravel 中,当你通过集合方法拉回数据时,它无论如何都会执行这个神奇的方法,因为所有属性都存储在称为属性的嵌套对象中,因此 __set() 和 __get() 看起来像这样: function __get($key){ return isset($this->attributes->{$key}) ? $this->attributes->{$key} : null; } function __set($key, $value){ return $this->attributes->{$key} = $value; } 建议后者带有属性子集,这样可以防止数据与返回的数据库列名称与模型中已使用的名称发生冲突。 这样,您只需在创建的每个模型中将一个属性名称作为保留名称进行管理,而不必担心您使用的数百个 var 名称会覆盖模型或模型扩展中的另一个属性名称。 使用该模型值来调用函数 $player = Player::get(); echo Player::getName($player->id,'PlayerInfoC'); 在 Player 模型中您只需调用 public static function getName($id,$class) return $class::where('player_id',$id)->getName();//each class will have the function } ps:您需要进行一些验证来测试该名称是否存在 另一种选择是在模型之间创建关系 您可以在模型中使用与以下相同的启动方法来执行此操作: protected static function booted() { if (<--your condition-- >) { $traitInitializers[static::class][] = 'boot' . ExampleTrait::class; $traitInitializers[static::class][] = 'boot' . Organizations::class; } }

回答 4 投票 0

创建包含轨道模型的 gem

我已经阅读了很多有关该主题的文章,但似乎没有什么能完全满足我的需求。如果我重复或不清楚某些事情,我很抱歉,因为我既是 ruby 和 Rails 的新手,也是 Stack Overflow 的新手。 我有...

回答 2 投票 0

在Rails中,如果枚举有空格,有没有办法访问其查询快捷方法?

我有一个带有名为“status”的枚举属性的模型。其中一个值(“进行中”)有一个空格。 班级游戏 < ApplicationRecord enum status: [:scheduled, :"in pro...

回答 1 投票 0

使用不同的模型进行保存与加载是否更好?

假设我正在创建一个表单,您可以在其中编辑人员记录。人员记录可能如下所示: 公开课人物 { 公共字符串 Id {get;放;} 公共字符串名称 {g...

回答 1 投票 0

ModuleNotFoundError:没有名为“keras.src”的模块 - Python

我正在尝试使用以下代码加载我的模型: `#加载模型 以 open('tomato_model.pkl', 'rb') 作为模型文件: #from keras.models 导入 load_model 模型 = pickle.load(model_file)` 但是...

回答 1 投票 0

Angular Api 请求与 id 上其他模型有关系的模型

假设我有如下所示的对象: 学生=[ { 编号: 1, 姓名:“萨拉”, 学校编号: 1, 卡号: 3, }, { 编号: 2, ... }, ] 学校=[ { 编号: 1, 名称:&

回答 1 投票 0

参数类型“对象?”无法分配给参数类型“String”。?

我的模型颤动项目有问题.. 我收到错误: 参数类型“对象?”无法分配给参数类型 '细绳'。 参数类型“对象?”无法分配...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.