How to obtain related table data in an Object data type

Options

I have a table 'profiles' which contains a column of object type. This holds 1 or more references to a table called 'clubs'. I want to pull the value of 'ClubName' from table 'clubs' when I fetch the profile records.

I watched the video 'Addons: Single vs List Return Types' provided by @Michael Udinski but my case is slightly different, in that Michael's has just ids, whereas mine has keys also, i.e.
clubs: [
{
clubs_id: 59,
clubs2_id: 28,
}

What I am looking for is something like this:

clubs: [
{
clubs_id: { id: 59, ClubName: 'Bristol City' }
clubs2_id: {id: 28, ClubName: 'Liverpool' }
}

Currently the returned data looks like this:

I tried a couple of ways to do this but could only get data for one of the clubs in the list

That appears to be so because it's only possible to select a single column, e.g.

I created an addon, to return a list (as from Michael's video) but that only attaches itself to one of the clubs not both.

Any suggestions anyone?

Thanks.

Best Answer

  • Mr_English
    Mr_English Member
    edited May 2023 Answer ✓
    Options

    @Michael Udinski I've solved it.

    To add the extra club, I mistakenly clicked the + button at the top. Instead, I should have added the additional clubs in the clubs_id column.🤦‍♂️

    Having done that, I was able to pull back related data using an add on, as per your video:

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi, does the object with club id's always have two club_ids in it?

    If yes then I think that addons are the way to go, but you need to apply them twice for both clubs_id and clubss_id, inside the array

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    @Mr_English - can you tell me more about your schema structure? What is the difference between clubs_id and clubs2_id? What does your clubs array set out to accomplish? I'm wondering if there's another structure that makes more sense here