![](/img/trans.png)
[英]Gorm : belongs to, struct model creating problem
一個 Post 應該屬於一個 User,並且與所屬的 User 有聯系,加上兩個 ID 都是 uuid 字符串。 這是我的帖子結構 model: 和我的用戶 model: 這是我用來創建帖子的 function 這是打印 output: 問題是 Post model (post.User) 的 cr ...
[英]Gorm : belongs to, struct model creating problem
一個 Post 應該屬於一個 User,並且與所屬的 User 有聯系,加上兩個 ID 都是 uuid 字符串。 這是我的帖子結構 model: 和我的用戶 model: 這是我用來創建帖子的 function 這是打印 output: 問題是 Post model (post.User) 的 cr ...
[英]How to create association with limit of items on rails
我有一個 model 與醫生和患者協會: Class doctor has_may:patients Class patient belongs_to:doctor 我需要限制免費支付患者和付費患者的其他限制。 我能給誰? 現在我的醫生沒有限制病人。 這是不對的。 ...
[英]How to use Laravel factory to create multiple models with 'belongsTo' relationships
我正在嘗試為我的應用程序創建一個單元測試,並希望測試是否存在關系。 對於我的場景,我有一個 model“服務”,它有一個屬於關系的“company_id”字段。 我想在我的測試中使用一個工廠來創建 10 個“服務”。 每個服務都應該有自己獨特的“公司” 我一直在靠近,我最近的嘗試是這樣的這是我服務中 ...
[英]Why my optional:true option is not working in my Rails model?
我正在努力進行以下遷移: 和 model: 當我嘗試在沒有所有者的情況下創建PartnerActivationHistory記錄時,會引發以下錯誤: PG::NotNullViolation: ERROR: null value in column "owner_id" of relation " ...
[英]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->control not building the proper <select> for the belongsTo association
我正在嘗試學習 CakePHP,但在處理關聯的方式上遇到了一些問題(可能只是我的誤解)。 我有一個 RESULTS 表,其中的復合鍵由表 WORKSHEETS 和 STUDENTS 中的兩個外鍵組成。 以下是結果、工作表和學生之間的關系。 結果 N - 1 名學生 結果 N - 1 個工作表 數據 ...
[英]How do you create and save an Active Record instance that has a reference to itself?
Files是一個 Active Record model,它引用了相同類型的父對象:class Files < ActiveRecord::Base belongs_to :parent, class_name: "Files" end 我想創建一個root條目,其父項是它自己(它模 ...
[英]Make Hidden child's relation /Laravel Eloquent
Model結構: AccessoryGroup組(有許多: accessories ) Accessory (屬於: accessory_group ) 獲取所有帶配件的配件組( accesory_group accessory_group ) 在accessories中,我需要access ...
[英]Deep relations, *child* relation depends on *great-grandparent* id - with | load - Laravel/Eloquent
我有這個數據庫/模型結構(示例): *食品類別 -------------- (id, name) - *不相關食物---------------------- (id, food_category_id, name, ...) 附件組-------- (id, name, ...) Foods ...
[英]Laravel belongsToMany - Get Parent All Categories
我不會說英語。 我很抱歉。 我想要做的是,獲取所有附加了 ID 為 5 的類別的類別 錯誤編輯在哪里? 數據庫: 分類.php 控制器 ...
[英]Storing information into the order and order_details table in one go
所以聽我說完。 如果我下訂單,我想存儲訂單和實際訂單詳情。 一張表存儲 orderID、productID、order_status 和 is_delivered,而另一張表包含送貨地址、價格和數量。 我已經設置了關系和所有內容,但我想弄清楚的一件事是: 如何從訂單中檢索 orderID,以便我可以 ...
[英]How do I update a foreign key (belongsTo) in Sequelize
我有以下 model: 然后我嘗試在收到userId 、 keyType和key后創建一行: 該行在數據庫中成功創建,我返回一個 ID( createdAt和updatedAt也更新了),但userId是 null。 我應該如何將它傳遞給create方法,以便將值傳遞給數據庫? 我在 model ...
[英]How to get posts by current tag and category simultaneously in Laravel?
我有 Post、Tag 和 Category 模型。 我知道如何按標簽或按類別獲取帖子。 但是我需要同時(一次)按選擇的標簽和類別獲取帖子。 有人可以幫忙嗎? 我使用 Laravel 8。 后 model 標簽 model 類別 model 后控制器的方法 路線 ...
[英]Rails : has_one and belongs_to same model
假設一個管理員可以是一個帳戶的所有者,一個帳戶可以有多個管理員。 您將有如下關聯: 該代碼無法正常工作,因為在管理員上定義了兩次的實例方法account相互沖突。 然后我會傾向於寫這樣的東西:class Administrator < ApplicationRecord has_one ...
[英]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 < ApplicationRecord has_many :bookings d ...
[英]How to make a Employee-Company relation in Rails?
我正在嘗試在 Ruby on Rails 上創建一個工作委員會。 我正在使用 devise 來處理帳戶,並且我有一個 Employee(設備用戶)和 Company 模型。 在這個挑戰中,當有人以員工身份創建帳戶時,我必須檢查公司域是否已經存在(該域是從員工電子郵件中提取的),如果不存在,則必須將 ...
[英]Sum of values in a has_many through - belongs_to association
在 Rails 6.1 項目上的 Ruby 項目中,我有Users可以選擇Activities列表。 每個Activity都有一個value 。 我想獲得所有用戶選擇的所有活動的總和。 我的模型是: 如前所述,在模式中, Activities有一個 integer 字段,我稱之為value ,每個活 ...
[英]Laravel 8 Using Belongs To Failing When Using Where
我知道這是我愚蠢並且不理解文檔,但我正在嘗試使用belongsTo功能來訪問 class 的父級在 model 我定義了 function 但是當我嘗試在 controller 中檢索它時出現錯誤 where 工作正常,因為它返回了正確的孩子,但我收到一個錯誤,說在嘗試獲取父母時Property ...
[英]Nodejs using Sequelize. “[].belongsTo called with something that's not a subclass of Sequelize.Model at Function.”
[學到的知識] 我正在遵循一個基本教程來學習 sequelize 及其關聯。 而這本書只展示了hasMany和belongsTo例子。 憑借短暫的知識,我正在碰壁創建一些數據模式。 [我想做什么] 數據模式基本上是關於軍事分支(或單位)的關聯。 Atom 單元是一個團隊。 一個團隊有一個直接 ...
[英]Laravel BelongsTo confusion
我在 EVENT 和 MAJOR 模型之間有一個 OneToMany 關系,如下所示: EVENT 屬於 Major 和 Major HasMany Events 這是我在 MySQl 中的表格 在控制器中,我將所有事件的數據傳遞給視圖,如下所示: 在我看來,我無法根據關系到達專業表: ...