草庐IT

identifying-relationship

全部标签

php - 如何在 Laravel 中使用 Eloquent Relationship 在 View 中显示两个表数据

我有两个表名称是User和Role表。我在LaravelEloquent中使用数据透视表名称Role_User设置了它们之间的manyTomany关系。现在,我想使用EloquentRelationship将两个表数据一起显示在一个View中。(例如,我想在我的View中显示users表中的用户包含roles表格)这里,是我的Eloquent关系。publicfunctionroles(){return$this->belongsToMany('App\Role');}publicfunctionusers(){return$this->belongsToMany('App\User'

php - Laravel Eloquent Relationships - 两个不同的送货地址与一个订单模型相关联

每个订单我有两个不同的送货地址:发票地址送货地址它们都有相同的字段,所以我只为它们创建了一个Address模型。模型:地址订单每个订单包含两个字段:发票地址送货地址我希望每个字段都指向同一个地址(如果用户希望将cargo运送到发票地址)或两个不同的地址(如果送货地址与发票地址不同)。我将如何为此目的建立关系?这是我尝试过的:订单.phppublicfunctionorderAddress(){return$this->hasOne('App\Address');}publicfunctiondeliveryAddress(){return$this->hasOne('App\Addre

php - Laravel Eloquent : belongsTo relationship - Error: Trying to get property of non-object

第一次尝试laraveleloquentrelatioinstip我知道这很简单,但我收到这个错误,不知道它出了什么问题我在数据库中有2个表,news和news_image在数据库中表格:newsid|header|detailsnews_imageid|image|news_id并且有2个模型News,newsImage新闻图像模型:classnewsImageextendsEloquant{protected$table='news_image';publicfunctionnews(){return$this->belongsTo('News');}}新闻模型classNewse

php - 我怎样才能加入 Eloquent : Relationships?

我的查询是这样的:user()->id)->get();return$reviews;}从query中,可以通过id获取所有review数据我要获取用户照片、店铺照片和产品照片我想使用Eloquent:Relationships如何通过Eloquent:Relationships获得它?我的评论模型是这样的:belongsTo(User::class);}}我的用户模型是这样的:hasOne(Store::class);}}我的店铺模型是这样的:hasMany(Product::class);}}我的产品模型是这样的:belongsTo(Store::class);}}

php - 拉维尔 4 : Will a soft delete on a table also apply to it relationships

我有一个名为'Titles'的表,我将向它添加软删除,但它还有几个引用此'Titles'表的其他表:目前,如果我删除一个标题,它将在标题详细信息处自动从所有其他引用的表格中删除。因此,如果我在执行删除时向'Titles'表添加软删除,它会在'titles'表上执行软删除,但会从引用表中删除详细信息?或者它会忽略onDeleteCascade请求并保留引用的数据吗?如果是第一个选项,那么我需要添加一个$table->softDeletes();到所有表引用。以及将protected$softDelete=true;添加到他们的模型中? 最佳答案

php - 代码点火器/数据映射器 : Two one-to-many relationships to the same table not working

我在与Codeigniter的DataMapper的关系方面遇到了这个问题.我有一个Interview模型,它有一个author_id和一个interviewee_id。它们都与用户模型中的用户ID相关。我一直在尝试几种方法,但都没有用;这就是我现在拥有的:classInterviewextendsDataMapper{var$has_one=array('interviewee'=>array('class'=>'user','other_field'=>'done_interview'),'author'=>array('class'=>'user','other_field'=>

php - Laravel 5 Eloquent 关系 : can't modify/overwrite relationship table property

我正在使用Laravel5的belongsToMany方法使用中间数据透视表定义相关表。我的应用程序使用Eloquent模型Tour和TourCategory。在Tour模型中,我有:namespaceApp;useIlluminate\Database\Eloquent\Model;classTourextendsModel{publicfunctioncats(){return$this->belongsToMany('App\TourCategory','tour_cat_assignments','tour_id','cat_id');}}在我的Controller中,我使用L

java - chalice /hibernate : No row with the given identifier exists

我有一个域名如下:classAuthor{StringidstatichasMany=[accounts:Account]staticbelongsTo=Accountstaticmapping={accountsjoinTable:[name:"SOMETABLE",key:'SOMEFIELD'],ignoreNotFound:true}staticconstraints={}}没有找到记录时出现以下错误。我试过ignoreNotFound,它不起作用。errormessage:accounts=org.hibernate.ObjectNotFoundException:Norow

java - JSR303 : Trying to customize a constraint violation to be associated with a sub-path in a class-level relationship constraint validator

我正在使用JSR303并创建了一个类级别的约束,用于比较表单中的密码及其确认,我将在此处命名为@SameAs约束。理想情况下,我希望将约束与预期目标(confirmPassword)相关联,但显然封闭的bean不可用于提取密码prop。-因此是类级约束。我感兴趣地阅读了其他展示如何利用类级约束来验证关系的帖子,但找不到任何解释如何自定义约束违规以与子路径相关联的内容,在本例中为关系中的两个字段。我的问题如下:如何将违反约束的消息与“confirmPassword”字段而不是顶级对象相关联?我尝试使用javax.Validator.validate(target,context)的上下文

java - Apache POI : API to identify tables in the excel sheet and read them

是否有任何方法可以返回工作表中存在的表格列表?我的要求是从工作表上存在的多个表中获取数据。 最佳答案 假设您正在为.xlsxexcel文件使用XSSFAPI。如果表格是由Insert->Table创建的,那么您可以使用以下命令读取它们:XSSFWorkbookworkbook=newXSSFWorkbook(newFile("test.xlsx"));intnumberOfSheets=workbook.getNumberOfSheets();for(intsheetIdx=0;sheetIdxtables=sheet.getTab