According to the README, the Update callback is only called on tables and views with a public key.
As far as I understand, SpacetimeDB does not allow marking a column as public key on views, though.
The solution is treating the identity or id column as primary key as a convention, but only if no "primary_key" is defined in the metadata:
|
# 1. Check metadata (preferred) |
|
if instance and instance.has_meta("primary_key"): |
|
var pk_field: StringName = instance.get_meta("primary_key") |
|
_primary_key_cache[table_name_lower] = pk_field |
|
return pk_field |
|
|
|
# 2. Convention: Check for "identity" or "id" field |
|
var properties = schema.get_script_property_list() |
|
for prop in properties: |
|
if prop.usage & PROPERTY_USAGE_STORAGE: |
|
if prop.name == &"identity" or prop.name == &"id": |
|
_primary_key_cache[table_name_lower] = prop.name |
|
return prop.name |
Unfortunately, all views contain a "primary_key" metadata field with value "", therefore instance.has_meta("primary_key") is always true, and the identity/id convention is always ignored.
|
set_meta('primary_key', '') |
I think the issue might be on this line, I think it's supposed to be primary_key_name.length()!=0 instead:
|
if table_names.size()!=0: |
I know a big refactoring is in-progress, so I am not opening a PR, but I still wanted to document this issue. Let me know if you'd like me to open a PR nonetheless.
Thank you!
According to the README, the Update callback is only called on tables and views with a public key.
As far as I understand, SpacetimeDB does not allow marking a column as public key on views, though.
The solution is treating the
identityoridcolumn as primary key as a convention, but only if no"primary_key"is defined in the metadata:Godot-SpacetimeDB-SDK/godot-client/addons/SpacetimeDB/core/local_database.gd
Lines 88 to 100 in a158a6b
Unfortunately, all views contain a
"primary_key"metadata field with value"", thereforeinstance.has_meta("primary_key")is alwaystrue, and theidentity/idconvention is always ignored.Godot-SpacetimeDB-SDK/godot-client/spacetime_bindings/schema/types/main_view_type.gd
Line 20 in a158a6b
I think the issue might be on this line, I think it's supposed to be
primary_key_name.length()!=0instead:Godot-SpacetimeDB-SDK/godot-client/addons/SpacetimeDB/codegen/codegen.gd
Line 241 in a158a6b
I know a big refactoring is in-progress, so I am not opening a PR, but I still wanted to document this issue. Let me know if you'd like me to open a PR nonetheless.
Thank you!