model 相关问题

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

拉拉维尔控制器和模型结构

这是一个很好的结构吗?或者我应该将其分为不同的控制器,例如(profilescontroller,GalleryController,settingsController,guardbook Controller)?

回答 2 投票 0

角:为什么我的shap值尺寸[sample_num,feature,class]而不是[class,sample_num,功能]?

为什么所有AI都认为塑形值按以下方式计算? x_sample = pd.dataframe(x_train_resampled,columns = x.columns)[:500] Invelimer_rf = shap.treeexplainer(rf_model) shap_value ...

回答 1 投票 0


django模型中的错误默认值

因此,我在我的Django模型中添加了一个新的末日。当我做“ Python3 Manage.py Makemigrations”时,它要求我选择两个选项,立即设置默认值或互相添加。我选择...

回答 1 投票 0







如何打印yolov5模型的模型摘要

如何打印.pt文件的Yolov5模型的模型摘要? # 模型 模型= TORCH.HUB.LOAD('ultrytics/yolov5','yolov5s',device ='cpu') 来自Torchstat Import Stat #try 1 Stat(型号,(3,640,640)) ...

回答 3 投票 0


我如何从这个Json

这是我现在的模型

回答 1 投票 0

在模型Django中,干净的功能有什么作用?不以形式

我正在阅读这个解决方案,我想知道“清洁功能”有什么作用? 我们应该在哪里进行检查吗? 然后我找到了这张照片 在此处输入图像描述 所以我们有很多

回答 1 投票 0



在模型中阅读JSON 我想在模型中使用其中的位置,但是它总是返回null afieten_id,我也想从活动表中获得的audieting_id详细信息。那就是为什么我在哪里使用 `

`<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Event extends Model { /** @use HasFactory<\Database\Factories\EventFactory> */ use HasFactory; protected $guarded =[]; protected $casts = [ 'audience_id' => 'json', 'location' => 'json', 'guest_type' => 'json', ]; public function audiences() { dd($this->audience_id); $audienceId = $this->audience_id['id'] ?? null; if ($audienceId) { return $this->hasMany(Audience::class, 'id')->whereIn('id', $audienceId); } return $this->hasMany(Audience::class, 'id')->whereIn('id', []); } }` 当我使用DD时,它总是返回零。这是我的桌子: `public function up(): void { Schema::create('events', function (Blueprint $table) { $table->id(); $table->string('category'); $table->string('title'); $table->json('location'); $table->json('audience_id'); $table->json('guest_type'); $table->integer('time_span'); $table->string('type'); $table->timestamps(); }); } ` 尽管我不知道为什么$this->audience_id为什么是空的,但我可以肯定的是,这不是应该使用雄辩的关系。 如果事件审计是一种一对多的关系,那么我希望在观众表中发生event_id。如果这是多对多的,我会使用一个枢轴表'audience_event'。 如果您坚持使用datamodel,则可以在事件模型中删除关系,而是使用setRelation()手动添加相关项目,例如: // Retrieve an event. $event = Event::first(); // Get the array of ids, expected contents are something like {"id": [1, 2, 3]}. $audienceIds = $event->audience_id['id'] ?? null; // Retrieve audiences. $audiences = Audience::whereIn('id', $audienceIds)->get(); // Add to the event. $event->setRelation('audiences', $audiences); then add($event);会显示这一点,好像模型中定义了实际关系。 App\Models\Event {#1337 ▼ // app\Http\Controllers\MyController.php:23 <snip> #relations: array:1 [▼ "audiences" => Illuminate\Database\Eloquent\Collection {#1345 ▼ #items: array:3 [▼ 0 => App\Models\Audience {#1347 ▶} 1 => App\Models\Audience {#1360 ▶} 2 => App\Models\Audience {#1359 ▶} ] #escapeWhenCastingToString: false } ] <snip> } 我不是雄辩的专家。也许有一种方法可以实现看起来更像您的代码的关系,但这很容易实现。 这似乎在这里的关系逻辑似乎有点过于复杂。 当您定义关系时,该方法是在数据实际检索之前调用的,这就是为什么您要恢复无效的原因。 // This gives null because data isn't loaded yet Event::with('audiences')->first(); // This gives the value of audience_id in the first row Event::first()->audiences; 由于在调用观众函数之前检索数据,因此此作用。 现在为解决方案部分, 看来您正在尝试在事件和受众之间建立关系。正确的数据库结构将在“受众表”表中具有event_id。然后,您可以定义这样的关系: 活动模型 public function audiences() { return $this->hasMany(Audience::class, 'event_id', 'id'); } 在观众模型中: public function event() { return $this->hasOne(Event::class, 'event_id', 'id'); } 如果您无法更改数据库,则另一种方法是使用类似的软件包 https://github.com/staudenmeir/eloquent-json-relations。虽然我没有亲自使用它,但它看起来可以解决您面临的问题。 您也是您所引用的一个问题:json field上的拉拉维尔·哈斯曼尼

回答 2 投票 0

当表已经有数据时,如何在 NodeJS 中使用 Sequelize 添加列?

我在项目中定义了模型,我需要在其中插入列,因为我刚刚将新列及其类型添加到特定的模型文件中。 也尝试过 {alter:true} 但...

回答 2 投票 0

Odoo 仍然记得模型中已删除的字段

我在模型及其视图中创建了一个字段,对其进行了测试并且它有效。然后后来删除了它,包括在数据库中。当我创建另一个字段并重新启动系统时,它会生成错误

回答 1 投票 0

Android 文本视图。参数化可以吗?可以绑定到模型吗?

我开始开发 Android 应用程序,我想知道: 是否可以对 TextView 进行参数化?我想呈现一条短信,其中注明:“用户年龄为 38 岁”。让我们

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.