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

pllaguno's avatar

Help on Relationships

i have a model called PowerBi, this model has a column called VehicleID which is of type UniqueIdentifier(MSSQL) in this table i can have repeated vehicles.

I have another table called vehicles, where i have all the possible vehicles. and the PK is VehicleID which matches the UID form the other table.

my relation is the following:

on PowerBi Model.

public function Vehicles(){
        return $this->belongsTo(Vehiculo::class,'VehicleID','VehicleID');
    }

and on the vehicle model:

public function PowerBi()
    {
        return $this->hasMany(PowerBi::class,'VehicleID','VehicleID');
    }

and when i ask for PowerBi::with('Vehicles') i get an sql error.

SQLSTATE[22018]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Operand type clash: uniqueidentifier is incompatible with tinyint (SQL: select * from [vehicle] where [vehicle].[VehicleID] in (79811, 15, 1, 10, 20, 21489, 2321962, 2, 3, 0, 4, 4, 4, 5, 6, 6, 6, 9657, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 101179, 1038599, 10, 10, 1120, 11, 11, 1238, 1311, 131, 135, 1458, 0, 152459, 152, 154, 0, 16, 170, 17356422, 17850, 17, 18, 1900000000, 1911570, 193, 1, 1, 1, 1, 1, 2147483647, 10000000, 1, 20174, 20, 20, 234, 23727711, 23, 24, 24, 252414, 254718, 255, 259456, 2599, 25, 262, 2147483647, 278735, 2830000, 288, 28, 29883, 2, 2, 2, 2, 2, 2, 2, 2, 30, 31307519, 313552, 31, 3293, 32, 3317, 33190189, 3378, 3390, 339, 2147483647, 34, 357, 357, 361022, 363257, 368, 3698, 36, 37255973, 374, 37, 37, 38, 390013, 396, 3, 3, 3, 3, 3, 3, 3, 0, 41861745, 423, 42617, 2147483647, 43548, 4368456, 43714917, 437, 43, 44, 44, 4535754, 455361, 4571, 2147483647, 46, 4713, 476, 477, 2147483647, 495, 4, 4, 4, 4, 4, 40000000, 4, 4, 4, 4, 4, 4, 509, 50, 51, 0, 541, 541, 5428, 548, 5494567, 54, 55272, 55, 5771, 57, 57, 57, 57000, 58, 5921, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 50000000, 2147483647, 5, 5, 6005, 61978439, 61, 61, 61, 62358, 6298819, 629, 63, 646, 64, 64, 65973, 668, 6719066, 672, 6740, 67, 67, 67, 6, 6, 6, 6, 6, 6, 6, 6, 7020, 7041727, 717944, 72655, 72930000, 72, 73, 751329, 778, 78, 78, 79713740, 79, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2147483647, 0, 7, 7, 7, 806555, 81, 81, 8220, 0, 83, 84104562, 84, 86, 8716, 87, 8824, 8957, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 800000000, 8, 8, 8, 8, 8, 908, 912, 9255533, 929849000, 92, 0, 95, 962, 9666, 967, 9682, 96, 97098663, 97, 981, 9839, 983, 98600, 98, 98, 99073096, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))"
0 likes
3 replies
Snapey's avatar

looks like you just need to ensure the column types are the same

I assume your vehicles table is using tiny int as its primary key.

by the way, conventionally, relationships should be lowercase and only classes have uppercase first letter

Do what you like whilst working on your own but if your project grows you will need to adopt coding standards

Please or to participate in this conversation.