-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Is there an existing issue?
- [x ] I have searched existing issues
Build info
- ObjectBox version: 4.4.0
- OS: macOS 15.6.1
- Device/chipset: Apple M1
Steps to reproduce
- create a struct with an Id field not named
id
that is annotated as the entity id - run generator
Expected behavior
The generated code compiles and matches mutable class id annotation behavior.
Actual behavior
The generated put(struct(s)
code always uses 'id' as the property name in the entity constructors.
Code
Code
Entity:
struct MyImmutableEntity: Entity {
// objectbox: id
let myId: Id
}
Generated:
extension ObjectBox.Box where E == MyImmutableEntity {
func put(struct entity: MyImmutableEntity) throws -> MyImmutableEntity {
let entityId: MyImmutableEntity.EntityBindingType.IdType = try self.put(entity)
return MyImmutableEntity(
id: entityId // Compile error, should be myId: entityId
)
}
func put(structs entities: [MyImmutableEntity]) throws -> [MyImmutableEntity] {
let entityIds: [MyImmutableEntity.EntityBindingType.IdType] = try self.putAndReturnIDs(entities)
var newEntities = [MyImmutableEntity]()
newEntities.reserveCapacity(entities.count)
for i in 0 ..< min(entities.count, entityIds.count) {
let entity = entities[i]
let entityId = entityIds[i]
newEntities.append(MyImmutableEntity(
id: entityId // Compile error, should be myId: entityId
))
}
return newEntities
}
}
I'm not at all familiar with Sourcery but from looking around it seems that the issue is here and here.
I assume the constructor template should be something like:
{{ prop.swiftName }}: entityId
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working