My schema has it that table A
has one B
which in turn has one C
.
When I fetch all A
, I can see in my returned data instead of a reference to B
; I just get it's id. This is what I want.
When I fetch A->with('B')
I get A
and object references all the way up to C
! I just want A
with B
references, not C
(which is a huge object, bloats my response, and contains sensitive data).
I want to do one of these two things. Either fetch A
with B
(no C
), or find a way to traverse the paginated (using LengthAwarePaginator
) object and strip the unwanted C
s.
Are any of these options possible in Laravel? Is there any other approach to achieve the same thing?
I finally found the problem. In my app, B was not subclassing Eloquent directly and in this parent class it was appending an extra attribute. Inside the getter for this attribute there was a call to C so no matter what I did, C was always being required by this appended attribute! I've removed all that unneeded subclassing and it now works as expected.