Show columns from relation on different connection?

I have tables that are related to each other on two different database connections (Integrating with a legacy system). For simplicity, say there is Users on one connection and Posts on the other. They are in a hasMany relation by Users.id and Posts.user_id. The Post model has
public function User(): BelongsTo {
return $this->belongsTo(User::class, 'id', 'user_id');
}
public function User(): BelongsTo {
return $this->belongsTo(User::class, 'id', 'user_id');
}
and the User model has
public function Posts(): HasMany {
return $this->hasMany(Post::class, 'id', 'user_id');
}
public function Posts(): HasMany {
return $this->hasMany(Post::class, 'id', 'user_id');
}
In the PostResource table() I have a column
Tables\Columns\TextColumn::make('User.name')
Tables\Columns\TextColumn::make('User.name')
I am not seeing the name of the User, nor any errors. Is it possible to show relationships over different database connections? The User and Post tables each do show their own data properly. Am I doing something wrong in general? Do I need a RelationshipManager? That seems overkill for just showing an item from the relation, I don't want to manage/edit/attach/detach/do other relationship operations.
2 Replies
Nuekrato
Nuekratoβ€’7mo ago
Try Tables\Columns\TextColumn::make('user.name') with a lower case u I am not sure if Filament is case-sensitive here Also in my experience Filament "silently fails" if a Form or Table field does not directly match with a Model's attribute That's the reason why you don't see an error or anything in the frontend
Boustrophedon
BoustrophedonOPβ€’7mo ago
The actual table is more like FooUser. I've tried foouser, FooUser, foo_user, & fooUser, which don't help. I'll go see if there is any way to fail loudly πŸ˜„ (I think this could be an Eloquent issue, too. relationships over different connections isn't very standard) I think I may have solved it: By using a HasOne relation instead of a BelongsTo. I'm not sure it feels "correct", though
Want results from more Discord servers?
Add your server