F
Filament14mo ago
Connor

ResourceManager not using new field names. (QueryException)

I've created a CheckoutItemsRelationManager for my CheckoutSessionResource, when i view the panel it gives me the following error..
Illuminate
 \ 
Database
 \ 
QueryException
PHP 8.2.5
10.26.2
SQLSTATE[HY000]: General error: 1 no such column: stripe_checkout_items.checkout_session_id
SELECT
count(*) AS aggregate
FROM
"stripe_checkout_items"
WHERE
"stripe_checkout_items"."checkout_session_id" = 3
AND "stripe_checkout_items"."checkout_session_id" IS NOT NULL
Illuminate
 \ 
Database
 \ 
QueryException
PHP 8.2.5
10.26.2
SQLSTATE[HY000]: General error: 1 no such column: stripe_checkout_items.checkout_session_id
SELECT
count(*) AS aggregate
FROM
"stripe_checkout_items"
WHERE
"stripe_checkout_items"."checkout_session_id" = 3
AND "stripe_checkout_items"."checkout_session_id" IS NOT NULL
I've created a CheckoutItemsRelationManager for my CheckoutSessionResource, when i view the panel it gives me the above error.. The issue is I've changed checkout_session_id to stripe_checkout_id, but Filament is still trying to find it with its old variable name? any help would be appreciated. I've updated the CheckoutItems.php reference to this variable & the migration for it. As well as clearing cache,config etc.
Solution:
Are you relying on Laravel's naming convention somewhere? If you have a relationship which implicitly uses that field name as the FK (so you didn't specify it in the relation function on the model), and you changed the field name without changing the table name, you would then have specify the FK name in the relationship function. Like ... ```php...
Jump to solution
4 Replies
Josh777
Josh77714mo ago
What about the relationship, have you updated the model refs?
Connor
ConnorOP14mo ago
I've updated it everywhere else, the resource manager still looks for checkout_session_id, there is no reference to this anywhere in my project only stripe_checkout_id.. I'm wondering if there is a way to specifically override it with the new id or something
Solution
cheesegrits
cheesegrits14mo ago
Are you relying on Laravel's naming convention somewhere? If you have a relationship which implicitly uses that field name as the FK (so you didn't specify it in the relation function on the model), and you changed the field name without changing the table name, you would then have specify the FK name in the relationship function. Like ...
public function checkoutSessions(): HasMany
{
return $this->hasMany(CheckoutSession::class);
}
public function checkoutSessions(): HasMany
{
return $this->hasMany(CheckoutSession::class);
}
... which would implicitly look for a 'checkout_session_id' field as the FK. If you then changed that FK field name, without now specifying it in that $this->hasMany(), things would break.
Connor
ConnorOP14mo ago
Yeah so i was setup similar to that.
public function checkoutSession()
{
return $this->belongsTo(CheckoutSession::class, 'stripe_checkout_id');
}

public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id');
}
public function checkoutSession()
{
return $this->belongsTo(CheckoutSession::class, 'stripe_checkout_id');
}

public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id');
}
I've updated to this, which has fixed the previous error, I cannot however see the releated items still, it just says there are none, but I can verify they are setup correctly in the DB.
Want results from more Discord servers?
Add your server