Below is my model schema. It allows users to "favorite" arbitrary objects, like blog posts, comments, etc. I feel like it makes most sense to store these as a composite primary key.
<object class="acUserFavorite" table="ac_user_favorite" extends="xPDOObject">
<field key="object_class" dbtype="varchar" precision="20" phptype="string" null="false" index="pk" />
<!-- object_class is a string identifying the type of object: acBlogPost, acComment, etc.. -->
<field key="object_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" index="pk" />
<field key="user_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" index="pk" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
<column key="object_class" length="" collation="A" null="false" />
<column key="object_id" length="" collation="A" null="false" />
<column key="user_id" length="" collation="A" null="false" />
</index>
</object>
If I manually enter rows into the database I can retrieve and remove them, but trying to save rows with xPDO only creates null values, and then throws a duplicate key error.
Is there a problem with my schema? I can’t figure out why it won’t save the correct values, yet still retrieves them.
I was able to get this working with a simple auto-increment primary key (xPDOSimpleObject), but I feel that that method is unsustainable. After a few months the primary key would be in the millions.
Edit: I’ve tried removing the length attribute in the index, but It doesn’t seem to make a difference. I basically copied the format from the modX schema.