CMS Development

SParry
Participant

HubDB Foreign ID column order

Here is what I am trying to achieve...

I have a table of videos with various information for each video.

I then want to create a table of "Learning modules". Each learning module will have X amount of videos in it. A video could be in multiple learning modules. Lastly the order in which the videos show up for a learning module is important.

Here is the problem...

I thought I could create a foreign ID column on the learning modules table, then select the videos that should be in the module from the videos table.

That does work, except the order in which I select the videos doesn't hold. After saving or publishing the order is changed in the column.

It looks like order changes to be ordered by video creation, so latest created video to the top.

Is it not possible to have the order hold?

Or can anyone else think of a different way to make this work? Unfortunately the order the videos appear in is very important.

0 Upvotes
6 Replies 6
ankitparmar09
Top Contributor

HubDB Foreign ID column order

Hello @SParry 

 

Thanks for reaching out. Good question. I can give code, it can help you.

 

{% for row in hubdb_table_rows(dynamic_page_hubdb_table_id, "&orderBy=-date") %}

{% endfor %}

0 Upvotes
SParry
Participant

HubDB Foreign ID column order

Thanks ankitparmar09, not sure this quite works either unfortunately. I can use that to order all the rows in a table. 

But I am wanting to only keep the order of the ids I select in a foreign ID column.

0 Upvotes
TDwebdev
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB Foreign ID column order

Hi SParry,

 

You can use the sort function:

{# here you can set the loop from hubdb #}
{% set my_posts = blog_recent_posts("default", limit=5) %}

{% for item in my_posts|sort(False, False, "name") %}
{{ item.name }}<br>


{% endfor %}

 



Vet Digital

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
SParry
Participant

HubDB Foreign ID column order

Thanks TDwebdev, but that doesn't actually help in this case.

There isn't actaully anything I can sort on, unless I am misunderstanding this.

Because a video can be in more than 1 learning module, and the order could be different for each learning module this won't work. We also don't want to order them by something like an alphabetical title.

Let me give you a simplified version of the data structure...

Tutorial videos (Over 100 videos)
id
page_title
page_description
video_url

Learning modules (Groups of videos under a theme < 10 at the moment. Not all videos are in a learning module)
id
page_title
page_description
videos (Was hoping to use foreign id column to select AND order the videos)

So we would then create a page for each learning module and on that page we would display a list of the videos for that module in the order they need to be in

As mentioned in the original post the foreign id column is not keeping the original order the videos are selected in when using this column type.

The only way I can think of to achieve this right now is to create a separate HubDB table for each learning module, with a row for each video in the learning module. Then have a foreign id column to select the video on each row. But is not very scalable.

So just looking for any other ideas people might have.

0 Upvotes
paradummy
Contributor | Partner
Contributor | Partner

HubDB Foreign ID column order

Hi SParry

If you know the maximum of videos a learning module can have, you could add as many columns to the table (video_1, video_2, video_3, etc.) and then loop through these columns. It's not the most pretty solution but that way you can have your custom order without additional tables. 

0 Upvotes
SParry
Participant

HubDB Foreign ID column order

Thanks paradummy. I already figured this one, but with one learning module having 11 videos (as the highest currently) that seemed like not the best solution. Also who knows how many they will need in the future.

0 Upvotes