-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk7TNLgACgkQW6QSU1GdvawPswCeL2E3QOmAtC7jROYLpt4Y+W7+
ZvkAnR2UMF/Q24QcyKKxNcib5lUlLS6u
=3+6J
-----END PGP SIGNATURE-----
Am 28.11.2011 03:27, schrieb Seb:
> 1. create an action called update_version, do a find_by_imei and update
> my model. This is actually what I do now but this isnt very restful or
> pretty
>
> 2. During create assign imei to phone.id... I like this solution for
> it's simplicity, but I cant get it to work (for reasons I'll explain if
> requested)
>
> 3. make two requests to the server. 1. where I do a find_by_imei and
> return the id 2. update normally
4. Make IMEI the primary key, but this is a quickshot and not well thought:
migration:
class MakeImeiThePK < ActiveRecord::Migration
def change
# Do Stuff that alters your referencing models and tables from id
# to imei
change_table :phones do |t|
t.remove_index :id
t.remove :id
t.add_index :imei
end
end
end
model:
class Phone < ActiveRecord::Base
set_primary_key :imei
[...]
end
This should provide you with a Phone.find() thats returning a Phone when
feeded with IMEI. Be sure to convert related models and tables BEFORE
you change the phones table or associations will be lost.
Also I am not sure if rails can handle foreign keys that are not int.
According to a StackOverflow answer I found[1], it is already something
hacky to use a non int as PK...
HTH
Norbert
No comments:
Post a Comment