CMS Development

RKnott
Member

One to Many HubDB Relationships

I am new to Hubspot, and just figuring things out with regard to how to technically manage my data in HubDB and Hubl to do what I want.  I have played with this for a while, and done quite a bit of searching, but somewhere along the line I seem to be missing how to accomplish this.

 

I am trying to identify how to both create a one to many relationship in HubDB and how to use Hubl to extract that data visually.  Here is what I am trying to do.  We have a horse rescue where we take in horses, then rehabilitate and retrain them and subsequently rehome them.  As a part of advertising them for adoption, we post a gallery of videos and photos, along with their bio data.  Additionally, periodically we have a horse that has been adopted out, returned, maybe because the adopter can no longer afford to keep the horse.

 

In a traditional relationsl DB, I would set this up as a table of Horses where I have thier statistics (breed, gender, height, bio, etc) then a table of Horse Vidoes where I would add new videos of horses as we make them.  This table would just have the name of the horse in the video and the video.  A similar table for Horse Photos with just horse name and photo.  Finally a Horse Adoption table where each adoption is stored for all horses and a colum with the horses name, adoptor information, date of adoption, etc.  This table will also store data on when a horse is returned and the reason.

 

Then when I want to display the data on a horse, I would go to the Horse table as my base table, plus pull up the multiple photos and videos of the horse from the linked tables of Horse Photos and Horse Videos, based on the many rows that match the horses name.  Finally, add in the adoption information of the horse, out of the Horse Adoption table that would show history of when adopted and when returned, and then when re-adopted out by someone else.

 

I have worked out how to do a one to one relationship and render that data, but somehow am missing how to do a one to many.  I know I could just pull up the child table, and do a filter based on the horse name in the Horses table, then build a loop to pull all associated records, but it seems that there should be an internal wey to actually link these tables and render the data via a function or dot notation, and I am just not seeing it clearly documented anywhere.

 

I have also thought about creating the horses as a custom object as well, but it appears as though that is not an option, as I have a Professional account, and it appears that is only an option with an Enterprise account.

 

Any assistance that you can provide me with how to configure this would be GREATLY appreciated!!

0 Upvotes
4 Replies 4
dennisedson
HubSpot Product Team
HubSpot Product Team

One to Many HubDB Relationships

Hey @RKnott 

First of all, love that you are working to help horses 😍

Custom Objects does feel like the better fit for this, but understand your limits. 

@Kevin-C , @alyssamwilie , @Teun , @miljkovicmisa  , can any of you lend a hand with this project? 

0 Upvotes
RKnott
Member

One to Many HubDB Relationships

I have not seen any other responses or suggestions...

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

One to Many HubDB Relationships

Will throw @remingtonbegg into the mix here as well 😉

0 Upvotes
remingtonbegg
Contributor | Elite Partner
Contributor | Elite Partner

One to Many HubDB Relationships

Thanks Dennis!

2 Big pieces I see that would work.

 

  1. HubDB of horses with a status field (active / inactive)
  2. HubDB of "Horse Media"
    1. Have a media type field
    2. Asset URL (Image / Video field)
    3. Child Table Association

If you use Dynamic Pages (from HubDB) than you should be able to pull the data by calling the "child table" and matching the id's. Alternatively you could use the page_slug column as your unique Identifier.
Link to Dynamic Pages with HubDB

Link to Multilevel Dynamic Pages

Link multiple HubDB Pages 

 

{% set horseid = <dynamic_page>.page_slug %}
{% set filter = "&horse_slug=" ~ horseid %}
{% set HorseDB = hubdb_table_rows(<tableId or name>, filter) %}

{% for media in horseDB %}
{{ media.file_url }}
{% endfor %}

Variables are examples