esbenp/architect

Allow sideloading to check for uniqueness using other identifiers than id

esbenp opened this issue · 3 comments

To check if a sideloaded resource already exists in the global scope, it should be allowed to check using something else than id

gruz commented

Hi. I use a preexisting database with uuid primary indexes like b504fabe-5782-4b62-89bd-f33f1d78449a instead of numeric indexes.

Currently Optimus is hardcoded to use index name id and index type of integer.

It's very easy to fix.
So lines like return (int) Utility::getProperty($entry, 'id'); (e.g. https://github.com/esbenp/architect/blob/master/src/ModeResolver/IdsModeResolver.php#L41 ) should be changed to return Utility::getProperty($entry, $entry->getKeyName());

And lines like
return $objectOrArray->{$property};
e.g. https://github.com/esbenp/architect/blob/master/src/Utility.php#L21
should be replaced with
return $objectOrArray->getAttributes()[$property];

I don't understand why the (int) is a must in your code. Anyway, we can define it by the Model property $incrementing

Is there any chance you are going to fix it soon?

Thank you very much!

@gruz you can do a pull request ;P

gruz commented

Submitted a pull request #5
I don't think it covers all possible situations, I know laravel not well enough. But in my case it works and I believe is a good start for your to fix other possible issues here.