cost 331 ms
Gorm:屬於,結構 model 創建問題

[英]Gorm : belongs to, struct model creating problem

一個 Post 應該屬於一個 User,並且與所屬的 User 有聯系,加上兩個 ID 都是 uuid 字符串。 這是我的帖子結構 model: 和我的用戶 model: 這是我用來創建帖子的 function 這是打印 output: 問題是 Post model (post.User) 的 cr ...

如何使用 Laravel 工廠創建具有“屬於”關系的多個模型

[英]How to use Laravel factory to create multiple models with 'belongsTo' relationships

我正在嘗試為我的應用程序創建一個單元測試,並希望測試是否存在關系。 對於我的場景,我有一個 model“服務”,它有一個屬於關系的“company_id”字段。 我想在我的測試中使用一個工廠來創建 10 個“服務”。 每個服務都應該有自己獨特的“公司” 我一直在靠近,我最近的嘗試是這樣的這是我服務中 ...

Gorm UUID 外鍵 - 屬於

[英]Gorm UUID foreign key - belongs to

我正在嘗試使用 GORM 在兩個數據庫表之間創建屬於關系,我的代碼如下:type Shop struct { ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid"` Name string `json:"name" go ...

Add.php Form-&gt;control 沒有建立正確的<select>對於 belongsTo 關聯

[英]Add.php Form->control not building the proper <select> for the belongsTo association

我正在嘗試學習 CakePHP,但在處理關聯的方式上遇到了一些問題(可能只是我的誤解)。 我有一個 RESULTS 表,其中的復合鍵由表 WORKSHEETS 和 STUDENTS 中的兩個外鍵組成。 以下是結果、工作表和學生之間的關系。 結果 N - 1 名學生 結果 N - 1 個工作表 數據 ...

深層關系,*孩子*關系取決於*曾祖父母* id - 與 | 加載-Laravel/雄辯

[英]Deep relations, *child* relation depends on *great-grandparent* id - with | load - Laravel/Eloquent

我有這個數據庫/模型結構(示例): *食品類別 -------------- (id, name) - *不相關食物---------------------- (id, food_category_id, name, ...) 附件組-------- (id, name, ...) Foods ...

將信息存儲到一個 go 中的 order 和 order_details 表中

[英]Storing information into the order and order_details table in one go

所以聽我說完。 如果我下訂單,我想存儲訂單和實際訂單詳情。 一張表存儲 orderID、productID、order_status 和 is_delivered,而另一張表包含送貨地址、價格和數量。 我已經設置了關系和所有內容,但我想弄清楚的一件事是: 如何從訂單中檢索 orderID,以便我可以 ...

如何在 Sequelize 中更新外鍵(belongsTo)

[英]How do I update a foreign key (belongsTo) in Sequelize

我有以下 model: 然后我嘗試在收到userId 、 keyType和key后創建一行: 該行在數據庫中成功創建,我返回一個 ID( createdAt和updatedAt也更新了),但userId是 null。 我應該如何將它傳遞給create方法,以便將值傳遞給數據庫? 我在 model ...

如何在 Laravel 中同時獲取當前標簽和類別的帖子?

[英]How to get posts by current tag and category simultaneously in Laravel?

我有 Post、Tag 和 Category 模型。 我知道如何按標簽或按類別獲取帖子。 但是我需要同時(一次)按選擇的標簽和類別獲取帖子。 有人可以幫忙嗎? 我使用 Laravel 8。 后 model 標簽 model 類別 model 后控制器的方法 路線 ...

Rails:has_one 和 belongs_to 相同 model

[英]Rails : has_one and belongs_to same model

假設一個管理員可以是一個帳戶的所有者,一個帳戶可以有多個管理員。 您將有如下關聯: 該代碼無法正常工作,因為在管理員上定義了兩次的實例方法account相互沖突。 然后我會傾向於寫這樣的東西:class Administrator &lt; ApplicationRecord has_one ...

使用 collection_select 通過 has_many 和 belongs_to 關聯在預訂中保存兩個類的 ID 保存時會拋出錯誤“必須存在”

[英]Using collection_select for saving ID of two classes in a booking through has_many and belongs_to association throws error 'must exist' when saving

我正在為學習軌道構建一個簡單的預訂應用程序。 我為人、汽車和預訂搭建腳手架。 現在,當我嘗試創建預訂時,我得到 2 個錯誤導致此預訂無法保存: 人必須存在汽車必須存在代碼car.rbclass Car &lt; ApplicationRecord has_many :bookings d ...

如何在 Rails 中建立員工-公司關系?

[英]How to make a Employee-Company relation in Rails?

我正在嘗試在 Ruby on Rails 上創建一個工作委員會。 我正在使用 devise 來處理帳戶,並且我有一個 Employee(設備用戶)和 Company 模型。 在這個挑戰中,當有人以員工身份創建帳戶時,我必須檢查公司域是否已經存在(該域是從員工電子郵件中提取的),如果不存在,則必須將 ...

has_many 到 - belongs_to 關聯中的值總和

[英]Sum of values in a has_many through - belongs_to association

在 Rails 6.1 項目上的 Ruby 項目中,我有Users可以選擇Activities列表。 每個Activity都有一個value 。 我想獲得所有用戶選擇的所有活動的總和。 我的模型是: 如前所述,在模式中, Activities有一個 integer 字段,我稱之為value ,每個活 ...

Laravel 8 使用時使用時屬於失敗的地方

[英]Laravel 8 Using Belongs To Failing When Using Where

我知道這是我愚蠢並且不理解文檔,但我正在嘗試使用belongsTo功能來訪問 class 的父級在 model 我定義了 function 但是當我嘗試在 controller 中檢索它時出現錯誤 where 工作正常,因為它返回了正確的孩子,但我收到一個錯誤,說在嘗試獲取父母時Property ...

Nodejs 使用 Sequelize。 “[].belongsTo 調用的不是 Sequelize.Model 在 Function 的子類。”

[英]Nodejs using Sequelize. “[].belongsTo called with something that's not a subclass of Sequelize.Model at Function.”

[學到的知識] 我正在遵循一個基本教程來學習 sequelize 及其關聯。 而這本書只展示了hasMany和belongsTo例子。 憑借短暫的知識,我正在碰壁創建一些數據模式。 [我想做什么] 數據模式基本上是關於軍事分支(或單位)的關聯。 Atom 單元是一個團隊。 一個團隊有一個直接 ...

Laravel 屬於混亂

[英]Laravel BelongsTo confusion

我在 EVENT 和 MAJOR 模型之間有一個 OneToMany 關系,如下所示: EVENT 屬於 Major 和 Major HasMany Events 這是我在 MySQl 中的表格 在控制器中,我將所有事件的數據傳遞給視圖,如下所示: 在我看來,我無法根據關系到達專業表: ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM