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
Look out for oracle reserved words,
My first bet is PROFILE
Leon L. 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.
On Tue, 2006-07-04 at 00:53 +0200, The A. wrote:
Leon L. 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
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
On Tue, 2006-07-04 at 01:20 +0200, The A. 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
On Tue, 2006-07-04 at 02:08 +0200, The A. 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
rake --tasks
rake db:schema:dump
Craig
this 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).
Craig W. wrote:
On Tue, 2006-07-04 at 00:53 +0200, The A. wrote:
Leon L. 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
That’s it ! I’ve changed :foreign_key => “ID_PROFILE” by :foreign_key =>
“id_profile” and it works.
Thanks a lot