For one of my objects it''s ''id'' will be taken from another system so I don''t want it auto_incrementing but I want to just assign a value myself to it? How can I create an id field while turning off auto_increment for it within a migration? Thanks my friends :-). -- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org http://www.kopanas.com http://www.cusec.net http://www.soen.info --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Kopanas wrote:> For one of my objects it''s ''id'' will be taken from another system so I > don''t want it auto_incrementing but I want to just assign a value > myself to it? How can I create an id field while turning off > auto_increment for it within a migration? >create_table(:table_name) <b>:id=>false</b> do |t| t.column :id, :int end The ":id=>false" is used all the time in associative(link) tables and should probably work in your case. You can also probably leverage before_create() to retrieve the id from your other table and then do attributes[:id] = <value you retrieved> I hope this helps... ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ilan Berci wrote:> create_table(:table_name) <b>:id=>false</b> do |t| > t.column :id, :int > end >Ouch, please ignore the <b> tags, I forgot where I was posting.. :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It works and it does not work :-). For some reason rails still does not like me assigning a value to id even if it is not a primary key. How can I resolve this? On 11/21/06, Ilan Berci <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ilan Berci wrote: > > > create_table(:table_name) <b>:id=>false</b> do |t| > > t.column :id, :int > > end > > > > Ouch, please ignore the <b> tags, I forgot where I was posting.. :) > > -- > Posted via http://www.ruby-forum.com/. > > > >-- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org http://www.kopanas.com http://www.cusec.net http://www.soen.info --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John -- You didn''t say what type of database you are using, but the place you should look is on ActiveRecord::ConnectionAdapters::AbstractAdapter -- prefetch_primary_key?() and next_sequence_value(). You should probably look at subclassing this class, and returning false from prefetch_primary_key?. That will cause next_sequence_value to be called, and you can do what you need to there. The return from this function is assigned to the id of the ActiveRecord instance. Take a look at the firebird or openbase adapters for examples. On 11/21/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > For one of my objects it''s ''id'' will be taken from another system so I > don''t want it auto_incrementing but I want to just assign a value > myself to it? How can I create an id field while turning off > auto_increment for it within a migration? > > Thanks my friends :-). > > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > http://www.kopanas.com > http://www.cusec.net > http://www.soen.info > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---