Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created June 2, 2011 21:59
Show Gist options
  • Save benhamill/1005427 to your computer and use it in GitHub Desktop.
Save benhamill/1005427 to your computer and use it in GitHub Desktop.
Order found merchants in SQL statement.
Situation:
- a user is trying to create an EMS for a merchant
- that merchant isn't a system merchant
- that merchant isn't a sync_user merchant for them
- there's an existing sync_user Merchant for someone else that matches based on
just the fqdn
- there's an existing Merchant that matches based on the full email
address
- the fqdn-matching merchant has a lower id than the
full-email-matching merchant.
Problem:
The code was set up such that it would find the fqdn-matching
merchant, decide it shouldn't be used for syncing, then try to create
a new full-email-matching merchant and run into the uniqueness
validation and fail out.
Solution:
Made the SQL statement that returns the merchant prefer to find a
full-email-matching merchant no matter the id order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment