topclaudy / compoships

Multi-columns relationships for Laravel's Eloquent ORM
MIT License
1.12k stars 130 forks source link

Invalid input syntax for type uuid #79

Open aliasbody opened 4 years ago

aliasbody commented 4 years ago

When using a uuid type as primary key, the relationship is made only using the first char and thus returns an input syntax error event when $incrementing is set as false and $keyType is set as string.

topclaudy commented 4 years ago

Can you share you models schemas and the definition of the relationships?

matalina commented 4 years ago

This was not a problem in 1.1.16 but is a problem in 1.1.17onward I have reverted my package to only use 1.1.16 and it removes the problem.

Below is the query that a relationship runs which works in 1.1.16 but not in 1.1.17

  SQLSTATE[HY000]: General error: 206 Operand type clash: uniqueidentifier is incompatible with tinyint [206] (severity 16) [select * from [ProdCode] where [ProdCode].[PCID] in (740, 4, 6, 7594778, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 108, 1156000000000, 11, 142, 14, 14, 15, 176, 188, 1, 1, 1, 20, 22, 0, 25464, 9223372036854775807, 269, 278, 2953, 2, 2, 2, 3013055, 30240254, 30505240, 319, 31, 339, 343, 354, 378, 3, 3, 43, 4557, 46543, 47, 484, 4970, 4, 0, 4, 4, 4, 4, 52, 53, 5400000, 55, 5, 5, 5, 5, 9223372036854775807, 6013, 63, 660884, 67, 6, 6, 0, 9223372036854775807, 6, 70, 713337, 9223372036854775807, 76298180, 764310, 7, 7, 7, 7, 9223372036854775807, 7, 7, 7, 7, 805, 9223372036854775807, 0, 8833, 88, 8900000000000000000, 9223372036854775807, 9312, 94114673, 974, 991, 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)] (SQL: select * from [ProdCode] where [ProdCode].[PCID] in (740, 4, 6, 7594778, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 108, 1156000000000, 11, 142, 14, 14, 15, 176, 188, 1, 1, 1, 20, 22, 0, 25464, 9223372036854775807, 269, 278, 2953, 2, 2, 2, 3013055, 30240254, 30505240, 319, 31, 339, 343, 354, 378, 3, 3, 43, 4557, 46543, 47, 484, 4970, 4, 0, 4, 4, 4, 4, 52, 53, 5400000, 55, 5, 5, 5, 5, 9223372036854775807, 6013, 63, 660884, 67, 6, 6, 0, 9223372036854775807, 6, 70, 713337, 9223372036854775807, 76298180, 764310, 7, 7, 7, 7, 9223372036854775807, 7, 7, 7, 7, 805, 9223372036854775807, 0, 8833, 88, 8900000000000000000, 9223372036854775807, 9312, 94114673, 974, 991, 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))

This is a straight-up relationship as follows:

public function product_code()
{
    return $this->belongsTo(ProductCode::class,'PCID','PCID');
}

And it must use your package because other models hook up to it with dual key and it doesn't always pick up. As I said it was working but now it's broken.

My Laravel is up to date as of 7.13.0

matalina commented 4 years ago

Verified it does not work with the 2.0.0 branch as well.

matalina commented 4 years ago

Changing the query to the below works:

public function product_code()
{
    return $this->belongsTo(ProductCode::class,['PCID'],['PCID']);
}

Correction this does not work in 2.0.0 so assuming it's not working in the prior versions

topclaudy commented 4 years ago

@matalina Thanks for the input. I'll investigate

yurii-github commented 3 years ago

hello

can you please retest your case on master branch? I have added some test coverage for your case (https://github.com/topclaudy/compoships/pull/108) but it looks like it was already fixed in master.

regards