Skip to content

db: preload embedded fields - #393

Open
xiam wants to merge 6 commits into
v3from
feature/preload
Open

db: preload embedded fields#393
xiam wants to merge 6 commits into
v3from
feature/preload

Conversation

@xiam

@xiamxiam commented Jul 20, 2017

Copy link
Copy Markdown
Member

The idea behind preloading is being able to map results from a join into an embedded type with ease:

artistCollection:=sess.Collection("artist")
publicationCollection:=sess.Collection("publication")
typeartistAssocstruct {
IDuint`db:"id"`...
}
typepublicationAssocstruct {
IDuint`db:"id"`...Author*artistAssoc`db:"author,omitempty,assoc"`
}
varpublications []publicationAssoc// Joining two db.Result objects by using Assoc.q:=publicationCollection.Find().Assoc(
artistCollection.Find("publication.author_id = artist.id"),
"author",
)

My proposal is adding an Assoc method which takes another db.Result from the same session and creates a JOIN behind the scenes. The second argument for Assoc is the name of the embedded field, in this case publicationAssoc has a Author *artistAssoc db:"author,omitempty,assoc"' field, that's why we use author as second argument for Assoc().

@xiamxiam changed the title db: Drafting support for "preload" featuredb: preload featureJul 20, 2017
@xiamxiam changed the title db: preload featuredb: preload embedded fieldsJul 20, 2017
@VojtechVitek

Copy link
Copy Markdown
Member

I'm not fully convinced this should be part of upper/db.

Same thing can be achieved with .Join().On() - am I right?

@xiam

xiam commented Aug 24, 2017

Copy link
Copy Markdown
MemberAuthor

@VojtechVitek Yes, except there is no join for db.Result so it won't work with Find(). Peter has expressed similar feelings towards another magical feature #394 (comment), and I have to admit that moving this to bond (which is more opinionated) sounds like a good idea.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@xiam@VojtechVitek