hood icon indicating copy to clipboard operation
hood copied to clipboard

Loading Relations

Open robfig opened this issue 11 years ago • 6 comments

I'm just curious if you were planning to handle loading of relations at any point?

e.g. If a User has an associated Account, would you say it should be represented as:

type User struct {
  AccountId hood.Id
}

and it's up to the user to select it separately when they want?

robfig avatar Feb 02 '13 16:02 robfig

Yes, I'd like to definitely implement that at some point, just don't know when (other stuff on my hands right now). If you want to help out - pull requests are always appreciated.

eaigner avatar Feb 02 '13 16:02 eaigner

I am working on this right now. I'll post a gist soon of how I am going to accomplish this so that I can get feedback. It is actually quite simple, you just need to alias all the columns in the SELECT with the tablename.column.

We could either transfer the column and container values into a map using the aliases as the key before mapping to the types or find a cleaner way.

I have also added FK contraints when you run CreateTable for hood.

Give me a couple days and I will have the basics for joining one to one and one to many relationships up on a gist.

crosbymichael avatar Apr 29 '13 17:04 crosbymichael

@eaigner @crosbymichael any update on this? Very much desired (although what I need -- eager loading a bunch of records -- might be more compolicated than a single belongs_to relationship.).

In Rails / ActiveRecord, you can do: User.where(...).all(include: {account: :subscription})

This lets you get a bunch of records with minimal SQL.

cypriss avatar Jul 03 '13 13:07 cypriss

+1

FreekKalter avatar Dec 08 '13 22:12 FreekKalter

I'm sorry, but I'm currently not longer actively maintaining hood (moved on to jet for more flexibility).

If anyone want's to jump in, I can add you as a contributor.

eaigner avatar Dec 09 '13 10:12 eaigner

Nobody add support?

weldpua2008 avatar Sep 01 '14 08:09 weldpua2008