Context: Synchronizing data with Microsoft's Graph API
Problem: Items have immutable ids that are case sensitive. There are many occurrences where unique items have the exact same Id, except for a single character having a different casing.
i.e.: (notice the 4th last character)
Item #1: EWg0AQbLDgfAFWEaaZsFuzmolNQAAAADDIQAA
Item #2: EWg0AQbLDgfAFWEaaZsFuzmolNQAAAADDiQAA
When using updateOrCreate() the underlying where() method generates a query against MySQL that returns a case insensitive result set.
Normally, I can get around this using whereRaw() and parameter binding, such as:
$id = 'casE seNsitive id';
Model::whereRaw("BINARY `graph_immutable_id`=?", [$id])->first();
However, for convenience, I would like to apply the same condition to updateOrCreate().
If I chain the above whereRaw() condition before updateOrCreate() it seems like it solves the issue:
Model::whereRaw("BINARY `graph_immutable_id`=?", [$id])
->updateOrCreate([], [$arrayOfProperties]);
From what I gather by skimming over the code base, this works because Builder will just add the extra condition onto the query, and I end up with the unique model.
Does anyone see any issue with this approach? Is there another way of going about this that I haven't thought of? (besides performing the raw query and then writing the code to either update or create manually)
Thanks