On Mon, Nov 28, 2011 at 8:54 PM, Colin Law <clanlaw@googlemail.com> wrote:
> On 28 November 2011 17:42, Sebastian <sebastianthegreatful@gmail.com> wrote:
>> On Mon, Nov 28, 2011 at 6:00 PM, Norbert Melzer
>> <timmelzer@googlemail.com> wrote:
>>> Am 28.11.2011 17:40, schrieb Sebastian:
>>>
>>>> Is there no way I can simply assign imei to phone.id during create?
>>>> That would make my life easier.
>>>
>>> Only when wiping the database and creating the phone-table withoud id,
>>> then creating the row id by hand as type integer.
>>>
>>
>> <snip />
>>
>> This isn't a live system. I'm developing as we speak.
>>
>> Right now I'm doing the following in my controller.
>>
>> 73 def create
>> 74 @device = Device.new(params[:device])
>> 75 @device.id = @device.device_id.gsub('-', '').to_i
>> ...
>>
>> (I dont care that I have two columns which contains the same data.
>> I've spend way too long time on different solutions already.)
>>
>> However this fails to work in my update method.
>>
>> 91 def update
>> 92 @device = Device.find(params[:id])
>> 93 @device.id = params[:device][:device_id].gsub('-', '').to_i
>> ...
>>
>> The resulting error message is:
>> Couldn't find Device with id=777666
>>
>> I've tried to @device.save after assigning to id with the same result.
>>
>> --
>> 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.
>>
>>
>
> Personally I advise against going against the convention of id being
> the primary key with its value determined by Rails. It is possible
> but it is hard work, and it is liable to be the sort of thing that
> continues to give grief over the years as Rails moves forward for
> example, and the method used to get round it no longer works. In your
> situation I would just include the imei as a separate field, pass that
> as a parameter in the form and use it to look up the record.
>
> The only situation where I would go against the convention is when I
> have a legacy database whose schema I cannot modify. And I mean
> *really* cannot modify.
>
I couldnt agree more. I have dropped the idea about using a secondary
column as PK.
--
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