On Nov 28, 2009, at 11:42 AM, Colin Law wrote:
> 2009/11/28 Ritvvij <[email protected]>:
>> Yup thought of what you said already but dont like it because already
>> my app has become huge:
>> 1. almost 14 reference tables and 10 app tables.
>> 2. 4 -5 deployments
>
> Do you mean that the table is an existing table in a legacy db? If so
> then google rails legacy and you will find how to use an existing
> field as the id. Even if it is not an existing table then sitll
> google it as you will find answers to your problem there.
>
>>
>> Every time I change some reference table with global impacts. I dont
>> want a new id because other application tables across all the
>> deployments might be using that particular reference table id. So I
>> want to fix up my reference table ids permanently by switching off
>> auto increment and taking control over it.
>
> Do you mean you will completely rewrite the table using a migration or
> similar, but wish to set specific id values? I believe in this case
> it is possible to force id fields to particular values even though it
> is nominally auto increment. Though I have not done it myself.
>
> Colin
>
> --
If you provide an id for a model, that id will be used.
ref = RefModel.new(fields) {|r| r.id = 42 }
ref.save
You can't assign the id in the attributes hash of the .new method
because ActiveRecord automatically protects the id from mass-
assignment. If you set the id in a block or in a separate statement,
then it will be used (unless it causes a conflict at the database
level because, for example, it has a unique index).
-Rob
Rob Biedenharn http://agileconsultingllc.com
[email protected]
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.