Closed krnsptr closed 6 years ago
That seems highly unlikely.
Can you add dd(Comment::find(123)->category())
to NotRelatedModel::debug()
and post the result?
in NotRelatedController
BelongsTo {#426 ▼
#child: ProgramStudi {#439 ▶}
#foreignKey: "id_perguruan_tinggi"
#ownerKey: "id"
#relation: "perguruan_tinggi"
#query: Builder {#434 ▼
#query: Builder {#417 ▼
+connection: MySqlConnection {#147 ▶}
+grammar: MySqlGrammar {#148 ▶}
+processor: MySqlProcessor {#149}
+bindings: array:6 [▼
"select" => []
"join" => []
"where" => array:1 [▼
0 => "11"
]
"having" => []
"order" => []
"union" => []
]
+aggregate: null
+columns: null
+distinct: false
+from: "perguruan_tinggi"
+joins: null
+wheres: array:1 [▼
0 => array:5 [▼
"type" => "Basic"
"column" => "perguruan_tinggi.id"
"operator" => "="
"value" => "11"
"boolean" => "and"
]
]
+groups: null
+havings: null
+orders: null
+limit: null
+offset: null
+unions: null
+unionLimit: null
+unionOffset: null
+unionOrders: null
+lock: null
+operators: array:30 [▶]
+useWritePdo: false
}
#model: PerguruanTinggi {#440 ▶}
#eagerLoad: []
#localMacros: []
#onDelete: null
#passthru: array:11 [▶]
#scopes: []
#removedScopes: []
}
#parent: ProgramStudi {#439 ▼
#table: "program_studi"
+timestamps: false
#fillable: array:3 [▶]
#appends: array:1 [▶]
#hidden: array:3 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:4 [▼
"id" => "1100011"
"nama" => "AGRIBISNIS"
"jurusan" => "1"
"id_perguruan_tinggi" => "11"
]
#original: array:4 [▼
"id" => "1100011"
"nama" => "AGRIBISNIS"
"jurusan" => "1"
"id_perguruan_tinggi" => "11"
]
#casts: []
#dates: []
#dateFormat: null
#events: []
#observables: []
#relations: []
#touches: []
#visible: []
#guarded: array:1 [▶]
}
#related: PerguruanTinggi {#440 ▼
#table: "perguruan_tinggi"
+timestamps: false
#fillable: array:1 [▶]
#appends: array:1 [▶]
#hidden: array:1 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#casts: []
#dates: []
#dateFormat: null
#events: []
#observables: []
#relations: []
#touches: []
#visible: []
#guarded: array:1 [▼
0 => "*"
]
}
#withDefault: null
}
in NotRelatedModel (note that the WHERE clause is missing):
BelongsTo {#439 ▼
#child: ProgramStudi {#454 ▶}
#foreignKey: "id_perguruan_tinggi"
#ownerKey: "id"
#relation: "perguruan_tinggi"
#query: Builder {#453 ▼
#query: Builder {#437 ▼
+connection: MySqlConnection {#147 ▶}
+grammar: MySqlGrammar {#148 ▶}
+processor: MySqlProcessor {#149}
+bindings: array:6 [▼
"select" => []
"join" => []
"where" => []
"having" => []
"order" => []
"union" => []
]
+aggregate: null
+columns: null
+distinct: false
+from: "perguruan_tinggi"
+joins: null
+wheres: []
+groups: null
+havings: null
+orders: null
+limit: null
+offset: null
+unions: null
+unionLimit: null
+unionOffset: null
+unionOrders: null
+lock: null
+operators: array:30 [▶]
+useWritePdo: false
}
#model: PerguruanTinggi {#436 ▶}
#eagerLoad: []
#localMacros: []
#onDelete: null
#passthru: array:11 [▶]
#scopes: []
#removedScopes: []
}
#parent: ProgramStudi {#454 ▼
#table: "program_studi"
+timestamps: false
#fillable: array:3 [▶]
#appends: array:1 [▶]
#hidden: array:3 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:4 [▼
"id" => "1100011"
"nama" => "AGRIBISNIS"
"jurusan" => "1"
"id_perguruan_tinggi" => "11"
]
#original: array:4 [▼
"id" => "1100011"
"nama" => "AGRIBISNIS"
"jurusan" => "1"
"id_perguruan_tinggi" => "11"
]
#casts: []
#dates: []
#dateFormat: null
#events: []
#observables: []
#relations: []
#touches: []
#visible: []
#guarded: array:1 [▶]
}
#related: PerguruanTinggi {#436 ▼
#table: "perguruan_tinggi"
+timestamps: false
#fillable: array:1 [▶]
#appends: array:1 [▶]
#hidden: array:1 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#casts: []
#dates: []
#dateFormat: null
#events: []
#observables: []
#relations: []
#touches: []
#visible: []
#guarded: array:1 [▶]
}
#withDefault: null
}
Do you have any scopes or other special features in your models?
Can you reproduce the problem using Category
and Comment
?
ah. sorry. I forgot how to reproduce it. a workaround came to my mind to avoid that problem, and my code base has been gone too far.
@krnsptr Amazingly annoying... I have a very similar problem and I just wasted a minute or two because you created a ticket, wasted people's time and didn't bother to follow up.
Description:
Eloquent relationship seems not working in another model when there is no relationship between the two models.
Example Code: