Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

movepixels's avatar

Mal-formed Query assistance

I am running a query and for some unknown reason the id's are getting edited.

I am using UUID, i checked the model and made sure the id in question is not being cast as something

query: "select * from `area_profiles` where `area_profiles`.`subscription_id` in (35, 9223372036854775807, 4);"

Thats how the query is executed on the correct id's

[
'35dd6aa2-5d58-11ec-8571-637e4e667455', 
'476e95bc-5d57-11ec-b970-6bf7dd401776', 
'4ed8e24e-5d57-11ec-9199-c94eecf3a4e3'
]

Hope someone might have an idea where to possible begin looking?

0 likes
6 replies
Tray2's avatar

What is the problem?

Should the query result be

[
'35dd6aa2-5d58-11ec-8571-637e4e667455', 
'476e95bc-5d57-11ec-b970-6bf7dd401776', 
'4ed8e24e-5d57-11ec-9199-c94eecf3a4e3'
]

if so what is the result you get?

Sinnbeck's avatar

Please show the code that generates the query

movepixels's avatar

Sorry, those are the correct id's that are in the database belonging to the user Its pretty deep in relations so try to break it down

Profile hasMany Subscription
Subscription belongsTo Area
Subscription hasOne Plan

and a join pivot table areas_profiles that holds the areas selected for that profile

So along the way the subscription_id's (array below is correct values in the db)

[
'35dd6aa2-5d58-11ec-8571-637e4e667455', 
'476e95bc-5d57-11ec-b970-6bf7dd401776', 
'4ed8e24e-5d57-11ec-9199-c94eecf3a4e3'
]

But when I log the query those ID's get mutated into

this is what those correct id's end up as

query: "select * from `area_profiles` where `area_profiles`.`subscription_id` in (35, 9223372036854775807, 4);"

Code to build query is pretty huge with multiple relations so not sure how to begin with that.

This is whats run

return new SubscriptionsCollection($profile->subscriptions()->active()->with(['plan', 'areas'])->get());

But thats like 8 different tables interacting, so I m starting and trying to find where the UUID's get changed into => 35, 9223372036854775807, 4

movepixels's avatar

Going to work backwards and try to figure it out where it gets altered

Firstly ensure correct id;s are getting pulled:

$profile->subscriptions->modelKeys();

Returns the correct values

[
    "35dd6aa2-5d58-11ec-8571-637e4e667455",
    "476e95bc-5d57-11ec-b970-6bf7dd401776",
    "4ed8e24e-5d57-11ec-9199-c94eecf3a4e3"
  ]

So thats fine,

Now to get the areas....

tykus's avatar

Are you using an incorrect type for a UUID foreign key column; e.g. your migration has been defined using unsignedBigInteger or foreignId?

movepixels's avatar

Thanks for the suggestion, but no i double checked, examined the tables in question to verify same Charset / Collation, CHAR(36), even ensured the tables / columns are same type.

Odd thing is I test with a user, that user has 3 different subscriptions, so thats fine, hence the 3 id's in this question. Each subscription allows to select a location / city, so for fun i selected the same city 3 times for each subscription so all say they have a subscription in Los Angeles.

DB shows 3 subscriptions, each subscription shows id for Los Angeles, dump the query shows 3 subscriptions, only 2 show the relationship Los Angeles, change a different city and it might show up or not.

Examine the database and the records / relationships save correctly.

At this point I am just going to re-build the models and see where something is messed up.

Please or to participate in this conversation.