On Mon, Nov 28, 2011 at 5:40 PM, Sebastian
<sebastianthegreatful@gmail.com> wrote:
> On Mon, Nov 28, 2011 at 5:27 PM, Norbert Melzer
> <timmelzer@googlemail.com> wrote:
>> Am 28.11.2011 15:57, schrieb Sebastian:
>>> On Mon, Nov 28, 2011 at 8:13 AM, Norbert Melzer
>>> <timmelzer@googlemail.com> 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
>> table altering.
>>
>>>> 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...
>>>>
>>>
>>> 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.
>>
>
> If dashes occours I'll strip 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:
>>
>> def self.find(imei)
>> self.find_by_imei(imei)
>> end
>>
>> eventually you need to tweak a little bit... Its a thought...
>>
>
> I cant comprehend the side effects of this. And The first solution of
> changing the pk to imei is turning into a nightmare... the imei nil
> and misc other stuff.
>
> Is there no way I can simply assign imei to phone.id during create?
> That would make my life easier.
>
Can't I just create a after_create filter and assign imei to phone.id ?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment