Skip to content

Commit e4bad71

Browse files
akoclaude
andcommitted
fix: write OQL inline on OqlViewEntitySource for Mendix 10.x
Mendix 10.x stores the OQL query on both the OqlViewEntitySource (inline "Oql" field) AND in a separate ViewEntitySourceDocument. Mendix 11.0+ removed the inline field. Our writer only created the separate document, causing CE6775 on 10.24. Add version-conditional serialization: when writing to a 10.x project, include the "Oql" field on the OqlViewEntitySource. The reflection data confirms: 10.21 has {oql, sourceDocument} while 11.0 has only {sourceDocument}. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7611937 commit e4bad71

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

mdl/executor/cmd_entities.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (e *Executor) execCreateViewEntity(s *ast.CreateViewEntityStmt) error {
353353
Attributes: attrs,
354354
Source: "DomainModels$OqlViewEntitySource",
355355
SourceDocumentRef: sourceDocRef,
356+
OqlQuery: s.Query.RawQuery,
356357
}
357358

358359
if s.CreateOrModify && existingEntity != nil {

sdk/mpr/writer_domainmodel.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/mendixlabs/mxcli/model"
1010
"github.com/mendixlabs/mxcli/sdk/domainmodel"
11+
"github.com/mendixlabs/mxcli/sdk/mpr/version"
1112

1213
"go.mongodb.org/mongo-driver/bson"
1314
)
@@ -573,9 +574,10 @@ func (w *Writer) serializeDomainModel(dm *domainmodel.DomainModel) ([]byte, erro
573574
}
574575

575576
// Entities array with version prefix 3
577+
pv := w.reader.ProjectVersion()
576578
entities := bson.A{int32(3)}
577579
for _, e := range dm.Entities {
578-
entities = append(entities, serializeEntity(e, moduleName))
580+
entities = append(entities, serializeEntity(e, moduleName, pv))
579581
}
580582

581583
// Associations array with version prefix 3
@@ -602,7 +604,7 @@ func (w *Writer) serializeDomainModel(dm *domainmodel.DomainModel) ([]byte, erro
602604
return bson.Marshal(doc)
603605
}
604606

605-
func serializeEntity(e *domainmodel.Entity, moduleName string) bson.D {
607+
func serializeEntity(e *domainmodel.Entity, moduleName string, pv *version.ProjectVersion) bson.D {
606608
// Attributes array with version prefix 3
607609
attrs := bson.A{int32(3)}
608610
for _, a := range e.Attributes {
@@ -661,7 +663,7 @@ func serializeEntity(e *domainmodel.Entity, moduleName string) bson.D {
661663

662664
// Add Source for view entities (references a ViewEntitySourceDocument)
663665
if e.Source == "DomainModels$OqlViewEntitySource" && e.SourceDocumentRef != "" {
664-
doc = append(doc, bson.E{Key: "Source", Value: serializeOqlViewEntitySource(e.SourceDocumentRef)})
666+
doc = append(doc, bson.E{Key: "Source", Value: serializeOqlViewEntitySource(e.SourceDocumentRef, e.OqlQuery, pv)})
665667
}
666668

667669
// Add Source for external entities (OData remote entity source)
@@ -767,13 +769,18 @@ func serializeGeneralization(parentRef string) bson.D {
767769
}
768770
}
769771

770-
func serializeOqlViewEntitySource(sourceDocumentRef string) bson.D {
771-
// OQL view source with reference to ViewEntitySourceDocument by qualified name
772-
return bson.D{
772+
func serializeOqlViewEntitySource(sourceDocumentRef, oqlQuery string, pv *version.ProjectVersion) bson.D {
773+
doc := bson.D{
773774
{Key: "$ID", Value: idToBsonBinary(generateUUID())},
774775
{Key: "$Type", Value: "DomainModels$OqlViewEntitySource"},
775-
{Key: "SourceDocument", Value: sourceDocumentRef},
776776
}
777+
// Mendix 10.x stores the OQL query inline on the source object (reflection data: 10.21 has "Oql" property).
778+
// Mendix 11.0+ removed this field; only the ViewEntitySourceDocument stores the OQL.
779+
if !pv.IsAtLeast(11, 0) {
780+
doc = append(doc, bson.E{Key: "Oql", Value: oqlQuery})
781+
}
782+
doc = append(doc, bson.E{Key: "SourceDocument", Value: sourceDocumentRef})
783+
return doc
777784
}
778785

779786
func serializeODataRemoteEntitySource(serviceName, entitySet, remoteName string, countable, creatable, deletable, updatable bool) bson.D {

0 commit comments

Comments
 (0)