草庐IT

belongstomany

全部标签

php - laravel belongstomany 有条件

我有以下模型。classTrainingextends\Eloquent{//Addyourvalidationrulesherepublicstatic$rules=['name'=>'required','city'=>'required','province'=>'required','budget_year'=>'required|integer','s_date'=>'required|date','e_date'=>'required|date'];//Don'tforgettofillthisarrayprotected$fillable=['name','city','

php - CakePHP 3.1 patchEntity 在清洁时总是将 belongsToMany 关联标记为脏

所以我注意到,如果我修补一个实体(编辑方法),并且如果它有belongsToMany关联,我是否对记录进行任何数据更改,它会将它们标记为脏。我希望如果我不对View中的BTM多选进行任何更改,数据就不会变脏,只有在多选中添加或删除选项才会在修补后将其标记为脏。数据确实保存正确,它只是脏了,但我需要采取行动知道它是脏的还是干净的,因为我的map表中有_join数据。映射表名为users_locations并具有id、user_id、location_id和static,其中static是一个tinyint/bool。我想做的是仅为新创建的映射表条目标记静态。我注意到patchEntity

mysql - Bookshelf(knex) - belongsToMany 关系不起作用

我一直在尝试使用belongsToMany关系(书架)在帖子和标签之间建立关系。这是我的代码:db.jsconstPost=bookshelf.Model.extend({tableName:'posts',hasTimestamps:true,tags:function(){returnthis.belongsToMany(Tag)}})constTag=bookshelf.Model.extend({tableName:'tags',posts:function(){returnthis.belongsToMany(Post)}})//PivottableconstPostTag=

php - Eloquent 具有多对多 (belongsToMany)

我有这个给定的表结构:如何使用Eloquent从我的“visita”类访问“curso.name”?我分配了多对多关系,但只能访问“turma.curso_id”,但我想得到类似$visita->curso['nome']的内容。我想知道如何避免需要Curso::all()。在下面添加了一些片段://ClassVISITAclassVisitaextendsModel{protected$fillable=['id','nome',];publicfunctionturmas(){return$this->belongsToMany('App\Models\Turma','turma_

php - Laravel 使用 belongstoMany 从 ID 获取模型

我正在使用Laravel4构建应用程序,但数据透视表存在一些问题。有3个表Categories,Products,products_categories(pivot)类别模型publicfunctionproduct(){return$this->belongsToMany('Product','products_categories');}产品型号publicfunctioncategory(){return$this->belongsToMany('Category','products_categories');}products_categories表有product_id和c

php - CakePHP 3 保存 BelongsToMany 关联未知类型 ""错误

我一直在用头撞墙试图找出为什么我的电子邮件(belongsToManyGuests(belongsToManyEmails))无法保存。当我尝试使用关联数据(guest)保存电子邮件模型时,它在$this->Emails->save($email)处失败,其中:未知类型“”错误无效参数异常此时,我已经按照CakeBookmarks示例(http://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html)进行了关系和编辑表单的T恤。甚至构建它并从中提取代码。这是我项目中的相关代码,感谢任何帮助或猜测:为em

mysql - 在 belongsToMany 关系中使用 name 列而不是 id

我有两个模型,一个是报价(用于报价表),另一个是品牌(用于品牌表)。这些模型之间存在“多对多”关系。我有一个表offer_brands,它映射了这两个表之间的关系。在此表中,我有将此表链接到优惠表的offer_id列和将此表链接到品牌表的品牌列使用品牌表中的品牌名称列。在品牌模型中,我想要一个返回所有报价的关系。我知道我可以做到这一点publicfunctionoffers(){return$this->belongsToMany(Offer::class,'offer_brands','offer_id','brand_id');//Butdon'thavebrand_idcolum

php - Eloquent many-to-many-to-many - 如何轻松加载远距离关系

我有3个表;用户、组和权限在模型中,我将关系设置为belongsToMany在用户模型中:publicfunctiongroups(){return$this->belongsToMany('Group');}在组模型中:publicfunctionusers(){return$this->belongsToMany('User');}publicfunctionpermissions(){return$this->belongsToMany('Permission');}在权限模型中:publicfunctiongroups(){return$this->belongsToMany(

mysql - Sequelize belongsToMany 不创建新表

使用sequelize,我期望这一行:m.User.belongsToMany(m.Company,{through:'UserCompany'});在我的数据库中生成一个名为“user_company”的新表,它将“用户”表和“公司”表链接在一起。然而,它并没有这样做。我是不是误解了文档说的意思ThiswillcreateanewmodelcalledUserProjectwithwiththeequivalentforeignkeysProjectIdandUserId.Whethertheattributesarecamelcaseornotdependsonthetwomode

php - Laravel belongsToMany 没有其中之一

我有两个表:categories和videos,然后我有一个数据透视表,因为它们是belongsToMany关系。我想要做的是获取所有视频,其中没有一个视频实例属于多个类别之一。例如视频1属于类别1、2和3。视频2属于类别1和3。视频3属于类别1。我想获取不属于类别2或3的视频,这意味着这将返回视频3。到目前为止,我已经尝试过,但没有给出预期的结果,这是因为仍然为视频1和2找到了另一行,因为它们属于类别1:Video::whereHas('categories',function($query){$query->whereNotIn('category_id',[2,3]);})->t