Error when adding a new table to the existing application

Deniz wrote:

table, that three digit DN was referring to another table being an
/*http://localhost:3000/cfg_dn*/
Application Trace http://localhost:3000/cfg_dn# | Framework Trace
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:192:in paginator_and_collection_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:174:in find_collection_for_pagination’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in process_without_session_management_support' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in each’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in require' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:192:in paginator_and_collection_for’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in send' c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in start’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’

And another thing is that I am able to see this table using Brio


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Could anybody give me more suggestions on this problem please? I’ve been
constantly trying to figure out for almost 2 weeks.
Please let me know if you guys need more feedback…
Thank you very much
Dnz…

Deniz wrote:

Deniz wrote:

Hi Everybody,
I am a newbie in this list so please forgive me if this is a lengthy
message.

What’s the schema?


Alex

Alex Y. wrote:

What’s the schema?

It connects to a remote oracle database through vpn…

Deniz wrote:

Alex Y. wrote:

What’s the schema?

It connects to a remote oracle database through vpn…
Right. So what’s the schema? What’s the table definition for cfg_dn?

Alex Y. wrote:

Right. So what’s the schema? What’s the table definition for cfg_dn?

Okey,
Sorry about that, Below is the table def for cfg_dn
DBID [DECIMAL(10,0), Required]
SWITCH_DBID[DECIMAL(10,0), Nullable]
TENANT_DBID[DECIMAL(10,0), Nullable]
TYPE [DECIMAL(38,0), Nullable]
NUMBER_ [VARCHAR2(255),Nullable]
ASSOCIATION [VARCHAR2(255),Nullable]
LOGIN_FLAG [DECIMAL(38,0),Nullable]
DN_LOGIN_ID [VARCHAR2(255),Nullable]
REGISTER_ALL [DECIMAL(38,0), Nullable]
GROUP_DBID[DECIMAL(10,0), Nullable]
TRUNKS [DECIMAL(10,0), Nullable]
ROUTE_TYPE[DECIMAL(38,0), Nullable]
OVERRIDE [VARCHAR2(255),Nullable]
STATE [DECIMAL(38,0), Nullable]
NAME [VARCHAR2(255),Nullable]
USE-OVERRIDE[DECIMAL[38,0],Nullable]
SW_SPECIFIC_TYPE [DECIMAL[38,0],Nullable]
CSID [DECIMAL(10,0), Nullable]
SWITCH_CSID [DECIMAL(10,0), Nullable]
TENANT_CSID [DECIMAL(10,0), Nullable]
GROUP_CSID[DECIMAL(10,0), Nullable]
PLACE_DBID[DECIMAL(10,0), Nullable]
PLACE_CSID[DECIMAL(10,0), Nullable]

As I mentioned before, I am not authorized to overide the tables. I
obtained the list using MSQUERY32.exe
Thanks…
Dnz

Deniz wrote:

It connects to a remote oracle database through vpn…

Right. So what’s the schema? What’s the table definition for cfg_dn?

Got it. I think it’s your TYPE column. ActiveRecord uses type as an
indicator for single table inheritance, and the code assumes the
content’s going to be a string, which is why it’s calling a string
method on it. Nasty little bug you’ve found there, and I can entirely
see why it’s been confusing. It’s funny, though - the MySQL adapter
distinguishes between TYPE and type, and gives a different error to
the one you’ve sent when the lower-case value is used. I can only
assume that the Oracle adapter for some reason allows that not to get
caught…

Try changing your app/models/cfg_dn.rb to look something like this:

class CfgDn < ActiveRecord::Base
def self.inheritance_column()
‘dontcare’
end
end

I haven’t tested it, but the inheritance_column() method should tell it
to look for a column named ‘dontcare’ when determining whether or not to
trigger single table inheritance. That column doesn’t exist, so the
failing method shouldn’t get triggered.

If it turns out not to be that, I reckon it’s got to be data-dependent.
I would suggest trying out the scaffolding on an empty database with
the same schema, and slowly add data in until you get it to fail…

Hope this helps,

Deniz,
It sounds to me like a referential integrity issue. ie… The table that
you are trying to change has a foreign key with ON DELETE CASCADE and/or
ON UPDATE CASCADE constraints. So when you attempt to change the table
your working on the database throws an error saying in effect “You can’t
do that because another table has a relationship to this me. Please
change that one first.”

If you can, extract your entire db as a sql statment. Then look for
something like:

CONSTRAINT BOOK_SECT FOREIGN KEY (SECTION_ID) REFERENCES
SECTION(SECTION_ID) ON DELETE CASCADE

It looks as if it may be DN_LOGIN_ID. Is that a three digit entry?

The foreign key may not be in the table your working on. Look for a
foreign ke reference to a row in your current table from another table.

Then again I could be totally off base. Crack being what it is and all.

Scott.

Alex Y. wrote:

What’s the schema?
see why it’s been confusing. It’s funny, though - the MySQL adapter
end
get it to fail…

Hope this helps,

Alex,
You are absolutely awsome. Thank you very much. It worked and I don’t
know how and why. I looked at your explanation and I changed the model
as you suggested. At first I put ‘Number’ in the place of ‘dontcare’ and
as a result I got the following error:

ActiveRecord::SubclassNotFound in Test#index

The single-table inheritance mechanism failed to locate the subclass:
‘Q410’. This error is raised because the column ‘number_’ is reserved
for storing the class in case of inheritance. Please rename this column
if you didn’t intend it to be used for storing the inheritance class or
overwrite CfgDn.inheritance_column to use another column for that
information.

|RAILS_ROOT: ./script/…/config/…|

Application Trace http://localhost:3000/test# | Framework Trace
http://localhost:3000/test# | Full Trace http://localhost:3000/test#

|c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:897:in instantiate_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:215:in instantiate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in
find_by_sql' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in find_by_sql’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:395:in
find' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:174:in find_collection_for_pagination’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:192:in
paginator_and_collection_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in paginate’
#{RAILS_ROOT}/app/controllers/test_controller.rb:8:in list' #{RAILS_ROOT}/app/controllers/test_controller.rb:3:in index’|

|c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:897:in instantiate_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:215:in instantiate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in
find_by_sql' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in find_by_sql’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:395:in
find' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:174:in find_collection_for_pagination’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:192:in
paginator_and_collection_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in paginate’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in perform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in perform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in process’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in handle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in require’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in require’
script/server:5|

|c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:897:in instantiate_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:215:in instantiate’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in
find_by_sql' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:431:in find_by_sql’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:395:in
find' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:174:in find_collection_for_pagination’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:192:in
paginator_and_collection_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in paginate’
#{RAILS_ROOT}/app/controllers/test_controller.rb:8:in list' #{RAILS_ROOT}/app/controllers/test_controller.rb:3:in index’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in perform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in perform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in process’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in handle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in require’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in require’
script/server:5|

Request

Parameters: None

Show session dump http://localhost:3000/test#


flash: !map:ActionController::Flash::FlashHash {}

Response

Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

So seeing the error, I changed back ‘dontcare’ to ‘dn_login_id’ and
voila…
I actually did not try to add the new table to the existing application
yet. I just created a new project to test out this. The next thing I am
gonna do is to integrate this apprach to my app.
And also how did you figure out this? I’ve been banging my head to the
wall over two weeks now. Could you please explain a little more how this
self.inheritence_colum() work? for example why do i need to have ‘self’
in front of inheritence_column()?
and How do I get more information about the methods like
inheritence_column()?
I greatly appreciate you help and again thank you.
Dnz…

Scott wrote:

Scott.

Scott,
thank you for your reply. From what I saw, DN_LOGIN_ID is empty for this
particular example. Actually DBID is three digit but what I am trying to
do actually is to search the database with Number_. Number_ is the four
digit actual DN I am looking for. The search was working with the DN 3
digit entry, now I am working on to do the same thing with Number_
Thanx.
Deniz.

Deniz wrote:

Alex Y. wrote:

So seeing the error, I changed back ‘dontcare’ to ‘dn_login_id’ and
voila…
I actually did not try to add the new table to the existing application
yet. I just created a new project to test out this. The next thing I am
gonna do is to integrate this apprach to my app.
And also how did you figure out this?
I thought I’d figured something out about data dependence (it had to be
doing something weird and data-related to be calling empty? on something
that clearly wasn’t internal to Rails), and then I spotted the first
line of the trace you emailed:

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:890:in
`instantiate_without_callbacks’

Lines 889 and 890 look like this:

if subclass_name = record[inheritance_column]
if subclass_name.empty?

Once I saw inheritance_column in there, and with your schema info
available, it clicked.

Could you please explain a little more how this
self.inheritence_colum() work?
It’s a class method that returns a single string. That string is used
(by a few other places in the code) to find the column which holds the
class name data for ActiveRecord subclasses to be instantiated as. It’s
documented clearer than I could probably explain it at
Peak Obsession.

for example why do i need to have ‘self’
in front of inheritence_column()?
That’s because it’s a class method, rather than an instance method.
Check here for more details:
http://www.rubycentral.com/book/tut_classes.html

Basically, it means that Rails doesn’t need an instance of the class
before it can find the information it needs to correctly create
instances. It’s a like a singleton method, if that terminology means
anything to you.

and How do I get more information about the methods like
inheritence_column()?
See http://api.rubyonrails.com. Oh, and the source code :slight_smile:

I greatly appreciate you help and again thank you.
No worries :slight_smile:
Oh, and a quick pointer, before you run into any more problems (although
you may have spotted this already) - You’re going to need to call
set_primary_key in CfgDn, because ActiveRecord won’t know which column
is unique in that table. Check the docs for more info on that.