Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time property in inlined struct #49

Open
jskop opened this issue Sep 24, 2023 · 0 comments
Open

Time property in inlined struct #49

jskop opened this issue Sep 24, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jskop
Copy link

jskop commented Sep 24, 2023

Code generator has problems with binding Time properties of inlined struct.
Consider following structs:

type Metadata struct {
	Id       uint64
	Created  time.Time `objectbox:"date"`
	Modified time.Time `objectbox:"date"`
}

type BlogPost struct {
	Metadata `objectbox:"inline"`
	Title    string
	Content  string
}

Generated entity definition does not contain Created and Modified properties:

var BlogPostBinding = blogPost_EntityInfo{
	Entity: objectbox.Entity{
		Id: 6,
	},
	Uid: 5152285828382661602,
}

// BlogPost_ contains type-based Property helpers to facilitate some common operations such as Queries.
var BlogPost_ = struct {
	Id      *objectbox.PropertyUint64
	Title   *objectbox.PropertyString
	Content *objectbox.PropertyString
}{
	Id: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &BlogPostBinding.Entity,
		},
	},
	Title: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &BlogPostBinding.Entity,
		},
	},
	Content: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &BlogPostBinding.Entity,
		},
	},
}

Additionally Load function looks like this (notice Created and Modified properties):

func (blogPost_EntityInfo) Load(ob *objectbox.ObjectBox, bytes []byte) (interface{}, error) {
	if len(bytes) == 0 { // sanity check, should "never" happen
		return nil, errors.New("can't deserialize an object of type 'BlogPost' - no data received")
	}

	var table = &flatbuffers.Table{
		Bytes: bytes,
		Pos:   flatbuffers.GetUOffsetT(bytes),
	}

	var propId = table.GetUint64Slot(4, 0)

	return &BlogPost{
		Metadata: Metadata{
			Id:       propId,
			Created:  Time{},
			Modified: Time{},
		},
		Title:   fbutils.GetStringSlot(table, 6),
		Content: fbutils.GetStringSlot(table, 8),
	}, nil
}

Expected behaviour: Inlined struct time properties are properly bound (just like regular properties)

Objectbox version: 1.7.0
Objectbox generator version: 0.13.0

@jskop jskop added the bug Something isn't working label Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant