Hi all, I''m using Rails/Mysql as development platform. the production server is under Rails/Oracle. Right now, i''m trying to install my application under the production server, the connection to orcale is fine via Rails, but i have a weird problem. example : here is a extract from my db scheme : Table User :_____________ id_user | first_name | last_name | login | password | id_profile | _________________________| Table Profile :__________ id_profile | name | _________________________| and my Models : class Profile < ActiveRecord::Base set_table_name "PROFILE" set_primary_key "ID_PROFILE" has_many :user end class User < ActiveRecord::Base set_table_name "user" set_primary_key "ID_USER" belongs_to :profil, :foreign_key => "ID_PROFILE" end with the rails console, I try the following command :>> x = User.find(1)=> #<User:0x454cf8b4 @attributes={"id_profile"=>1, "first_name"=>"Nom", "last_name"=>"Prenom", "password"=>"test", "login"=>"login", "id_user"=>1}> That''s fine. but when iwant to get the user profile :>> x.profile=> nil>> x.profile.nameNoMethodError: You have a nil object when you didn''t expect it! The error occured while evaluating nil.name from (irb):12 knowing that i did not have any problems with Mysql, what could be the problem with Oracle ? Could you help me please ? thanks -- Posted via http://www.ruby-forum.com/.
Look out for oracle reserved words,,,, My first bet is PROFILE On 7/3/06, The Allnighter <theallnighter@gmail.com> wrote:> > Hi all, > I''m using Rails/Mysql as development platform. the production server is > under Rails/Oracle. > Right now, i''m trying to install my application under the production > server, the connection to orcale is fine via Rails, but i have a weird > problem. example : > here is a extract from my db scheme : > > Table User :_____________ > id_user | > first_name | > last_name | > login | > password | > id_profile | > _________________________| > > Table Profile :__________ > id_profile | > name | > _________________________| > > and my Models : > class Profile < ActiveRecord::Base > set_table_name "PROFILE" > set_primary_key "ID_PROFILE" > has_many :user > end > > class User < ActiveRecord::Base > set_table_name "user" > set_primary_key "ID_USER" > belongs_to :profil, > :foreign_key => "ID_PROFILE" > end > > with the rails console, I try the following command : > >> x = User.find(1) > => #<User:0x454cf8b4 @attributes={"id_profile"=>1, "first_name"=>"Nom", > "last_name"=>"Prenom", "password"=>"test", "login"=>"login", > "id_user"=>1}> > > > That''s fine. but when iwant to get the user profile : > >> x.profile > => nil > >> x.profile.name > NoMethodError: You have a nil object when you didn''t expect it! > The error occured while evaluating nil.name > from (irb):12 > > knowing that i did not have any problems with Mysql, what could be the > problem with Oracle ? > Could you help me please ? thanks > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Never be afraid to try something new. Remember, amateurs built the ark; professionals built the Titanic! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060703/337e8d94/attachment.html
The Allnighter
2006-Jul-03 22:53 UTC
[Rails] Re: Migrations from Mysql to Oracle. PLS HELP!
Leon Leslie wrote:> Look out for oracle reserved words,,,, > > My first bet is PROFILEThank you for your reply. i have the same problem with the other tables of the database (example: region, ville, commune) and i don''t think they are reserved word. it seems that all the relationships doesn''t work in active record once i''ve switched to oracle. -- Posted via http://www.ruby-forum.com/.
On Tue, 2006-07-04 at 00:53 +0200, The Allnighter wrote:> Leon Leslie wrote: > > Look out for oracle reserved words,,,, > > > > My first bet is PROFILE > > Thank you for your reply. > i have the same problem with the other tables of the database (example: > region, ville, commune) and i don''t think they are reserved word. > it seems that all the relationships doesn''t work in active record once > i''ve switched to oracle.---- my thinking was if the column name is id_profile, then the foreign key should be ''id_profile'' not ''ID_PROFILE'' - I don''t think that there is any forgiveness in the case of these objects...the same is true of table names, etc. Craig
The Allnighter
2006-Jul-03 23:20 UTC
[Rails] Re: Re: Migrations from Mysql to Oracle. PLS HELP!
> my thinking was if the column name is id_profile, then the foreign key > should be ''id_profile'' not ''ID_PROFILE'' - I don''t think that there is > any forgiveness in the case of these objects...the same is true of table > names, etc. > > CraigThe problem is that the production database is a legacy database and other applications are working with it. I had to use some workaround to "shortcut" rails conventions :( -- Posted via http://www.ruby-forum.com/.
Craig White
2006-Jul-03 23:36 UTC
[Rails] Re: Re: Migrations from Mysql to Oracle. PLS HELP!
On Tue, 2006-07-04 at 01:20 +0200, The Allnighter wrote:> > my thinking was if the column name is id_profile, then the foreign key > > should be ''id_profile'' not ''ID_PROFILE'' - I don''t think that there is > > any forgiveness in the case of these objects...the same is true of table > > names, etc. > > > > Craig > > The problem is that the production database is a legacy database and > other applications are working with it. I had to use some workaround to > "shortcut" rails conventions :(---- try doing a rake schema_dump and see what rails calls the tables & columns Craig
The Allnighter
2006-Jul-04 00:08 UTC
[Rails] Re: Re: Re: Migrations from Mysql to Oracle. PLS HELP!
> try doing a rake schema_dump and see what rails calls the tables & > columnsi have this error message : rake aborted! Don''t know how to build task ''schema_dump'' did i missed something ? -- Posted via http://www.ruby-forum.com/.
Craig White
2006-Jul-04 00:18 UTC
[Rails] Re: Re: Re: Migrations from Mysql to Oracle. PLS HELP!
On Tue, 2006-07-04 at 02:08 +0200, The Allnighter wrote:> > try doing a rake schema_dump and see what rails calls the tables & > > columns > i have this error message : > rake aborted! > Don''t know how to build task ''schema_dump'' > did i missed something ?---- rake --tasks rake db:schema:dump Craig
The Allnighter
2006-Jul-04 00:40 UTC
[Rails] Re: Re: Re: Re: Migrations from Mysql to Oracle. PLS HELP!
> rake --tasks > > rake db:schema:dump > > Craigthis is the result of the command : # Could not dump table "region" because of following ActiveRecord::StatementInvalid # OCIError: ORA-00918: column ambiguously defined: SELECT lower(i.index_name) as index_name, i.uniqueness, lowe r(c.column_name) as column_name FROM user_indexes i, user_ind_columns c WHERE i.table_name = ''REGION'' AND c.index_name = i.index_name AND i.index_name NOT IN (SELECT index_name FROM user_constraints WHERE constraint_type = ''P'') ORDER BY i.index_name, c.column_position I have the same error message in the db/schema.rb file for all the database tables (OCIError: ORA-00918: column ambiguously defined). -- Posted via http://www.ruby-forum.com/.
The Allnighter
2006-Jul-04 17:45 UTC
[Rails] Re: Re: Migrations from Mysql to Oracle. PLS HELP!
Craig White wrote:> On Tue, 2006-07-04 at 00:53 +0200, The Allnighter wrote: >> Leon Leslie wrote: >> > Look out for oracle reserved words,,,, >> > >> > My first bet is PROFILE >> >> Thank you for your reply. >> i have the same problem with the other tables of the database (example: >> region, ville, commune) and i don''t think they are reserved word. >> it seems that all the relationships doesn''t work in active record once >> i''ve switched to oracle. > ---- > my thinking was if the column name is id_profile, then the foreign key > should be ''id_profile'' not ''ID_PROFILE'' - I don''t think that there is > any forgiveness in the case of these objects...the same is true of table > names, etc. > > CraigThat''s it ! I''ve changed :foreign_key => "ID_PROFILE" by :foreign_key => "id_profile" and it works. Thanks a lot :) -- Posted via http://www.ruby-forum.com/.