MODX3 ExtraBuilder Custom table auto_increment?

Hello,

I thought the id field for a custom table in ExtraBuilder is created automatically?

The table created without id auto_increment field.

So, I added an field id, but how could I tell ExtraBuilder to create an auto_increment?

Schema Version: 3.0

Thanks for help and clarification.

Bye
Chris

If you extend xPDO\Om\xPDOSimpleObject for your class/table, then it creates an “id” column for you automatically.

If you extend xPDO\Om\xPDOObject however, you have to add the “id” column yourself.

oh, thank you.
and how could I create attribute “auto_increment”?

With an index. The schema would look something like this:

<object class="MyClass" table="myprefix_myclass" extends="xPDO\Om\xPDOObject">
	<field key="id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
	...

	<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
		<column key="id" length="" collation="A" null="false" />
	</index>
</object>

great.

I placed:


	<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
		<column key="id" length="" collation="A" null="false" />
	</index>

under “Raw XML (Define additional rules or schema values for edge cases)”

but the id field created, is not auto_increment.

What do I have made wrong?

I think I made a mistake. It seems you have to add index="pk" generated="native" to the field to make it work:

how could I add this in Manage fields in ExtraBuilder?
Till now I haven’t managed to create an id field in ExtraBuilder that is auto_increment

I’m not that familiar with ExtraBuilder.

Can’t you just change the “Extends Object (Default xPDOSimpleObject)*:” property of the ‘Object’ to xPDO\Om\xPDOSimpleObject, so it creates the primary key automatically?

To manually create a primary key, maybe try the field “Additional Attributes” or “Generated” (= native).

If I change it to xPDOSimpleObject is it still schema 3.0 for modx3?

Probably not.

You can preview the schema in ExtraBuilder (“Schema Actions” → “Preview Schema”).
It should look like this:

<object ... extends="xPDO\Om\xPDOSimpleObject">

with this changes, now it runs.
the builder creates the id field with auto_increment.

Many thanks :pray:

1 Like