I am mapping ActiveRecord classes to an existing Oracle database. This means I cannot change the database schema to fit ActiveRecord conventions. Predictably, I have gotten into trouble: I have several join tables that do not have a primary key column, and therefore no number sequence defined. ActiveRecord insists on requiring a sequence, and gets unhappy when there is none to find. Is there a way to tell ActiveRecord not to expect a sequence number (and no primary key)? /Henrik Mårtensson --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Jan-23 11:47 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
On Jan 23, 2007, at 12:15 PM, Henrik wrote:> I am mapping ActiveRecord classes to an existing Oracle database. This > means I cannot change the database schema to fit ActiveRecord > conventions. > > Predictably, I have gotten into trouble: I have several join tables > that do not have a primary key column, and therefore no number > sequence > defined. ActiveRecord insists on requiring a sequence, and gets > unhappy > when there is none to find.Regular join tables have no primary key normally in Rails. Do you mean those tables would naturally map to Rails join models? -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Anthony Carlos
2007-Jan-23 14:52 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
Henrik: I asked the same question months ago and got no responses. Even though I said :id => false during my migration, AR complained (ORA-02289: sequence does not exist) that it needed a sequence. I created the sequence manually just for kicks, and AR complained (ORA-00904: invalid identifier) that it couldn''t insert into an id column. Duh, there is no id column because we don''t want one. So, I looked further into the docs for AR::Base and tried set_sequence_name (nil) and got ORA-00936: missing expression: select .nextval from dual. Thus, AR was still trying to use a sequence without a name. I removed set_sequence_name and tried using set_primary_key to one of my columns, and AR inserted the sequence number into that column. So, I do not know how to tell AR not to use a sequence number. But I thought I''d document what I''ve tried in case anyone else wants to compare notes. Has anyone else gotten any further on this? Thanks, -Anthony On Jan 23, 2007, at 6:15 AM, Henrik wrote:> > I am mapping ActiveRecord classes to an existing Oracle database. This > means I cannot change the database schema to fit ActiveRecord > conventions. > > Predictably, I have gotten into trouble: I have several join tables > that do not have a primary key column, and therefore no number > sequence > defined. ActiveRecord insists on requiring a sequence, and gets > unhappy > when there is none to find. > > Is there a way to tell ActiveRecord not to expect a sequence number > (and no primary key)? > > /Henrik Mårtensson > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ian Zabel
2007-Jan-25 02:19 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
I have just run into a very similar issue. I have a legacy schema, and the primary key is a char(3) column. There is obviously no sequence. class Developer < ActiveRecord::Base set_table_name "developer" set_primary_key "developerid" end In my view, the user is allowed to fill in an ''id'' field (maxlength="3"), and in the create action, I manually set the id: @developer = Developer.new(params[:developer]) @developer.id = params[:id] When I try to save this, I get the error: ORA-02289: sequence does not exist There has got to be a way to disable the auto-sequence feature of ActiveRecord... Anyone? On Jan 23, 9:52 am, Anthony Carlos <anth...-icZdIMMiY0Opv2MiSiIzJgC/G2K4zDHf@public.gmane.org> wrote:> Henrik: > > I asked the same question months ago and got no responses. Even > though I said :id => false during my migration, AR complained > (ORA-02289:sequencedoes not exist) that it needed asequence. I > created thesequencemanually just for kicks, and AR complained > (ORA-00904: invalid identifier) that it couldn''t insert into an id > column. Duh, there is no id column because we don''t want one. So, I > looked further into the docs for AR::Base and tried set_sequence_name > (nil) and got ORA-00936: missing expression: select .nextval from > dual. Thus, AR was still trying to use asequencewithout a name. I > removed set_sequence_name and tried using set_primary_key to one of > my columns, and AR inserted thesequencenumber into that column. > > So, I do not know how to tell AR not to use asequencenumber. But I > thought I''d document what I''ve tried in case anyone else wants to > compare notes. > > Has anyone else gotten any further on this? > > Thanks, > > -Anthony > > On Jan 23, 2007, at 6:15 AM, Henrik wrote: > > > > > I am mapping ActiveRecord classes to an existingOracledatabase. This > > means I cannot change the database schema to fit ActiveRecord > > conventions. > > > Predictably, I have gotten into trouble: I have several join tables > > that do not have a primary key column, and therefore no number > >sequence > > defined. ActiveRecord insists on requiring asequence, and gets > > unhappy > > when there is none to find. > > > Is there a way to tell ActiveRecord not to expect asequencenumber > > (and no primary key)? > > > /Henrik Mårtensson--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ian Zabel
2007-Jan-25 04:37 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
Well, I somehow got past this problem in my code. I guess I just wasn''t properly assigning the id somehow. Got my form right and as long as an id is set on the new record, the sequence will not be called. Here''s the relevant code from the create method in ActiveRercord''s base.rb: if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name) self.id connection.next_sequence_value(self.class.sequence_name) end Maybe you can try overriding that method with a version of your own to get around your problem with composite keys. Or maybe something like http://compositekeys.rubyforge.org/ would help? On Jan 24, 9:19 pm, "Ian Zabel" <ianza...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have just run into a very similar issue. I have a legacy schema, and > the primary key is a char(3) column. There is obviously nosequence. > > class Developer < ActiveRecord::Base > set_table_name "developer" > set_primary_key "developerid" > end > > In my view, the user is allowed to fill in an ''id'' field > (maxlength="3"), and in the create action, I manually set the id: > > @developer = Developer.new(params[:developer]) > @developer.id = params[:id] > > When I try to save this, I get the error: > ORA-02289:sequencedoes not exist > > There has got to be a way to disable the auto-sequencefeature of > ActiveRecord... > > Anyone? > > On Jan 23, 9:52 am, Anthony Carlos <anth...-icZdIMMiY0Opv2MiSiIzJgC/G2K4zDHf@public.gmane.org> wrote: > > > Henrik: > > > I asked the same question months ago and got no responses. Even > > though I said :id => false during my migration, AR complained > > (ORA-02289:sequencedoes not exist) that it needed asequence. I > > created thesequencemanually just for kicks, and AR complained > > (ORA-00904: invalid identifier) that it couldn''t insert into an id > > column. Duh, there is no id column because we don''t want one. So, I > > looked further into the docs for AR::Base and tried set_sequence_name > > (nil) and got ORA-00936: missing expression: select .nextval from > > dual. Thus, AR was still trying to use asequencewithout a name. I > > removed set_sequence_name and tried using set_primary_key to one of > > my columns, and AR inserted thesequencenumber into that column. > > > So, I do not know how to tell AR not to use asequencenumber. But I > > thought I''d document what I''ve tried in case anyone else wants to > > compare notes. > > > Has anyone else gotten any further on this? > > > Thanks, > > > -Anthony > > > On Jan 23, 2007, at 6:15 AM, Henrik wrote: > > > > I am mapping ActiveRecord classes to an existingOracledatabase. This > > > means I cannot change the database schema to fit ActiveRecord > > > conventions. > > > > Predictably, I have gotten into trouble: I have several join tables > > > that do not have a primary key column, and therefore no number > > >sequence > > > defined. ActiveRecord insists on requiring asequence, and gets > > > unhappy > > > when there is none to find. > > > > Is there a way to tell ActiveRecord not to expect asequencenumber > > > (and no primary key)? > > > > /Henrik Mårtensson--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael A. Schoen
2007-Jan-25 07:23 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
Ian Zabel wrote:> Well, I somehow got past this problem in my code. I guess I just wasn''t > properly assigning the id somehow. Got my form right and as long as an > id is set on the new record, the sequence will not be called.Correct, that''s the expected/correct behavior -- so long as you define the PK properly, and set it yourself, it won''t try to use a sequence. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Henrik
2007-Jan-26 00:51 UTC
Re: ActiveRecord requires sequence numbers in Oracle join table
Thank you for the replies, everyone! I am going to hack the create method. Looks like it is the best option. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Cowdery
2007-Mar-01 00:11 UTC
Re: ActiveRecord requires sequence numbers in Oracle join ta
Ian Zabel wrote:> I have just run into a very similar issue. I have a legacy schema, and > the primary key is a char(3) column. There is obviously no sequence. > > class Developer < ActiveRecord::Base > set_table_name "developer" > set_primary_key "developerid" > end > > In my view, the user is allowed to fill in an ''id'' field > (maxlength="3"), and in the create action, I manually set the id: > > @developer = Developer.new(params[:developer]) > @developer.id = params[:id] > > When I try to save this, I get the error: > ORA-02289: sequence does not exist > > There has got to be a way to disable the auto-sequence feature of > ActiveRecord... > > Anyone?ActiveRecord looks at the id attribute to see if it needs to generate an id using a sequence, or if its already been supplied. Unfortunately when you use your own primary key AR still looks at the id column. You can get around this by aliasing id to your own primary key attribute. in the example above you can just add the following to the Developer class alias developerid id alias developerid= id that way you can get and set developerid and it will update self.id so active record won''t bother trying to use the sequence. -enjoy! -Brian -- 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 -~----------~----~----~----~------~----~------~--~---