Change/add fieldnames from Modelname Biz.Sphinx

Hi,

I have a guestion about TMS Sphinx.

Is it possible to use other tables and field names instead of the ones from ModelNames Biz.Sphinx in AureliusDBSchema? What would be the best way to get this working?

Regards.

You can extend the existing user entity with more properties and more business logic. It's explained here:

But other than this, why do you want to change the name of tables and fields? Any reason for that?

I would like to use the same naming convention for tables/fields which are used in my web application.

In theory you could access the underlying Aurelius metadata (Sphinx uses Aurelius for database operations) and modify table and field names there. You just must be sure to do that at the beginning of the application, before any database operation is performed.

var EntityType := TMappingExplorer.Get(cSphinxModelName)
  .GetEntityTypeFromClass(Sphinx.Entities.TUser);
EntityType.Table.Name := 'sx_users_new';
EntityType.Properties.Find('FUserName').Columns[0].Name := 'user_name_new';
...

GetEntityTypeFromClass couldn't be found. Instead FindEntityTypeFromClass was used.

var EntityType := TMappingExplorer.Get(cSphinxModelName).FindEntityTypeFromClass(Sphinx.Entities.TUser);

However table- and fieldname are not changed.

As said, you have to make sure you do those changes before any database operation, are you sure you did that?

I start without database file and let the application create one.

The changes are done before any database operation.

procedure TForm1.FormCreate(Sender: TObject);
begin
var EntityType := TMappingExplorer.Get(cSphinxModelName).FindEntityTypeFromClass(Sphinx.Entities.TUser);

Showmessage(EntityType.Table.Name);
Showmessage(EntityType.Properties.Find('FUserName').Columns[0].Name);

EntityType.Table.Name := 'sx_users_new';
EntityType.Properties.Find('FUserName').Columns[0].Name := 'user_name_new';

AureliusConnection1.Params.Values['Database'] := ChangeFileExt(ParamStr(0), '.db');

AureliusDBSchema1.UpdateDatabase;

SparkleHttpSysDispatcher1.Active := True;
end;

Here is also the test project.
Sphinx1.zip (75.8 KB)

Well, cSphinxModelName should be Biz.Sphinx.
For some reason, in your test project is TUsers. Just fix it and it should work.

Thanks for the correction. Got it working.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.