Am 28.11.2011 15:57, schrieb Sebastian:
On Mon, Nov 28, 2011 at 8:13 AM, Norbert M.
[email protected] wrote:
Am 28.11.2011 03:27, schrieb Seb:
This should provide you with a Phone.find() thats returning a Phone when
feeded with IMEI.
There is no disadvantage to this? Is this a rails 3 feature?
I dont know about disadvantages, but I never tested… Also I dont know
if this is rails 3 or could work with earlier versions. Its just a hack
that I found on stackoverflow by googling around. I never tried this.
Be sure to convert related models and tables BEFORE
you change the phones table or associations will be lost.
This is related to existing data? Because otherwise I’m not sure what you mean.
Dunno… To say that I have to know your existing database structure,
but how should I?
If you have any models that are belonging to a phone, then you have to
change their foreign key (phone_id) to the IMEI instead of the ID. Also
you have to alter the type of that column if needed, could be much of
Also I am not sure if rails can handle foreign keys that are not int.
According to a StackOverflow answer I found, it is already something
hacky to use a non int as PK…
IMEI are ints. Atleast the ones I’ve encountered so far.
I had IMEIs in the head with dashes, also my phone reports it with
dashes. But according to wikipedia this dashes are only for grouping and
readability, they are not used when transferring them, or at least can
be stripped if your clients transmits them.
But as I am writing, another possibility came into my mind.
But I dont know how that works with belonging models…
Just overide the find-method in your model, like this:
eventually you need to tweak a little bit… Its a thought…
In any case, I would create another branch and test there in a sondbox
if you are using a VCS, in any other case I would try it in another
When all your existing tests are passing after changes then you could do
manually testing, and if that also shows no breakages, then you can
deploy and merge.
But hold back a backup, could be better. And I am talking about a
database backup also!