ActiveRecord: Class does not have a table registered for it

Hello everyone,

I’m trying to get a web project off the ground with the help of ARGen and ActiveRecord. I’ve been able to load the DB successfully but the app is failing at some point when I try to load a listbox with the data from one of my tables.

After running the db file through ARGen and loading the classes on my web project, I add a build step to copy the db to the app’s parent folder for debugging.

The db file has a number of tables, but I’m interested on the one called t_need. It has a number of attributes, including stitle (TEXT) and it is already preloaded with a couple of records.

This is what I have on App’s Open() event (Console shows DB loads ok when I run it):

  dim f as FolderItem = GetFolderItem("db.sqlite")
  if f <> nil then
    if Data.OpenDB(f) = True then
      System.DebugLog "DB file loaded successfully"
      System.DebugLog "DB file NOT loaded"
    end if
  end if

And this is the code I have been trying to use in the Open() event of the main page containing the listbox:

  For each oRecord as Data.t_need in Data.t_need.List()
    lbMain.AddRow oRecord.stitle
    lbMain.RowTag(lbMain.LastIndex) = oRecord

When I run the code above, I get a nil object exception at the line below:

ex.Message = "Class does not have a table registered for it: " + ty.FullName


Have you Registered the Table with ActiveRecord? It’s usually part of the Data module.

It looks like ARGen has done that work already. This is from Data.OpenDB(f as FolderItem)

  //Register the tables with ActiveRecord
  Register( gdb )

And from Data.Register(db as SQLiteDatabase)

  BKS_ActiveRecord.Table( db, "t_need", GetTypeInfo( t_need ) )

All I can say is that it’s not being called. Follow in the Register method in the debugger to verify that it’s actually being registered.

Another thought: Is it possible that you’re referencing another table in the t_need object and the referenced table is what’s not registered?

No luck. It looks like the Register() call is being executed:

The t_need table has user_id and region_id columns that link to t_user/t_region tables but both are also being registered in the Register() method.

If you can send me the project I can help diagnose. Try support at bkeeney dot com.