Just create a model method findByZip(), adjust the search param, and call Parent::findByZip($zip)
I think I'd run $zip through a regexp to see if you need to pass the substring only, rather than potentially making 2 queries of the DB. This is an RE for Canadian postal codes: ^[ABCEGHJ-NPRSTVXY]{1} [0-9]{1} [ABCEGHJ-NPRSTV-Z]{1} [ ]? [0-9]{1} [ABCEGHJ-NPRSTV-Z]{1} [0-9]{1}$ I fugured it would have wrapped badly. Stick those lines together, without spaces. On Wed, Feb 25, 2009 at 4:47 PM, psujohn <psuj...@gmail.com> wrote: > > So for some reason we want to handle Canada differently from the US. > We have a model that has a zip and for US we do stuff like ->findByZip > ('20007') but for Canada we want to put partial postal codes in the db > and have ->findByZip('N1M 1M2') match an entry in the db that has just > 'N1M' listed as the zip code. > > My Canadian friends will have to forgive me for referring to their > postal codes as zip codes but beyond that is there a good way to > handle this? > > What I did was add a method in the model that I called getByZip and in > there do: > $x = $this->findByZip($zip); > if (!$x) $x = $this->findByZip(substr($zip, 0, 3)) > > What I'd like is some way to magically alter the magic findByZip > method so that is provides the desired behavior without having to > resort to changing every place that calls the method. Ideas? > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---