Questions tagged [polymorphic-relationship]
44 questions
3
votes
0 answers
Laravel Nova does not distinguish between different types of polymorphic relationship between same models
I have a Tab model which has a one-to-many polymorphic relationship with many other models including my User model. I've called this relationship customizers (because they customize a tab's content) and store them in a table called tab_customizers…

TheSETJ
- 518
- 9
- 25
2
votes
2 answers
sqlalchemy.exc.InvalidRequestError: Row with identity key can't be loaded into an object; the polymorphic discriminator column refers to mapped class
I have some legacy code that has a polymorphic base class definition and two sub classes.
The entity definitions are below.
class Field(Base):
__tablename__ = "field"
field_parent = Column(String(64), index=True)
controller_id =…

dirk345
- 21
- 1
2
votes
1 answer
Apply where condition to related models in polymorphic relation laravel 8
I am facing an issue in Polymorphic relations where I can not make whereHas to work. The relation code is working fine to return the related models, but need to apply where conditions to the relations of the models connected with the polymorphic…

Jayesh Kannan
- 45
- 6
2
votes
0 answers
query polymorphic relationships with related models in laravel 8
So I want the corresponding items that belong to the correct relationship so when the type is App\\Models\\Post it should get a post item with it and if the type is App\\Models\\Comment it should get a comment with it etc
The query
$result =…

HashtagForgotName
- 651
- 1
- 7
- 23
2
votes
0 answers
How to save Laravel Multi Polymorphic Relationship?
I have a scenario that needs two polymorphic relationship in one model. The main model is Calls which includes a Caller and Callee. Caller and Callee can be a User, Buyer or Seller. So I designed my table like following.
class Call extends Model
{
…

Can Atuf Kansu
- 523
- 2
- 7
- 16
2
votes
2 answers
Get all records based on Model type in Polymorphic Relations
I have 3 Models and the related tables: Firm, SaleFirm, PartnerFirm.
In the Firms Table i want to store general informations about firms like name, bank account, ID and stuffs like this. In the other two tables i will store different informations…

Ioan Andrei
- 93
- 1
- 16
2
votes
3 answers
Laravel 5.8 polymorphic relation `nullableMorphs` not working
I have a table for attachments, that has polymorphic relation with other tables. I want to upload a file on file select and insert it to the attachments table, but this record is not related to any parent table until the parent record is created, so…

jones
- 1,423
- 3
- 35
- 76
2
votes
1 answer
How to fix error "Please use whereHasMorph() for MorphTo relationships." when using search function of Laravel BackPack?
I have a very simple One-to-Many polymorphic relationship as following.
posts
id - integer
title - string
videos
id - integer
title - string
comments
id - integer
body - text
commentable_id - integer
…

O Connor
- 4,236
- 15
- 50
- 91
1
vote
0 answers
Laravel multiple polymorphic relationship
I have a database tables as followed
Posts Table
Comments Table
Users Table
Pages Table
Likables…

drhtoo
- 11
- 2
1
vote
2 answers
hasManyThrough with morph
I have a projects table that either can be assigned to a user or a team, this is the structure:
id
assignable_id
assignable_type
class Project extends Model {
public function assignable(): MorphTo
{
return $this->morphTo();
…

Mohammad Zahed
- 19
- 7
1
vote
1 answer
Laravel 8: One To Many Polymorphic: Relate same child to different parents
I used the one-to-many polymorphic relationship like described in the laravel documentation, to be able to relate different parent models to one child model. i have assumed, that i would be able to assign different parent models to the same child…

lsblsb
- 1,292
- 12
- 19
1
vote
0 answers
What is the standard and professional way to query Laravel polymorphic relations?
Trying to fetch persons table based on the result of the polymorphic relations. What is the professional standard way on doing this? Thank you very much!
Insertable model
public function insertables() {
return $this->morphMany(Insertable::class,…

codevour
- 11
- 1
1
vote
0 answers
Custom Polymorphic Types in Laravel
I am working with polymorphic relationships and created a polymorphic tables with columns like
posts -:
| id(integer) | title(string) | body(text) |
videos -:
| id(integer) | title(string) | url(text) |
comments -:
| id(integer) |…

kumudgupta76
- 354
- 3
- 10
1
vote
1 answer
How to save additional/extra columns of the polymorphic morphable model in Laravel (7)?
Take a many-to-many polymorphic relationship sample from the Laravel docs website.
posts
id - integer
name - string
videos
id - integer
name - string
tags
id - integer
name - string
taggables
tag_id - integer
…

O Connor
- 4,236
- 15
- 50
- 91
1
vote
1 answer
Querying laravel polymorphic many to many relationships
I have estate_object table which holds information about estate, for example: address, city, region etc.
Then i have a seperate tables which holds just specific property of an object, for example on of the tables is objects_near.
I made seperate…

Richard Wolf
- 21
- 3