Merging two collections on server

I have two database queries which return the same structure, and I need to combine them. The queries themselves are derived from completely different data sets, so I can’t combine them directly from the database.

I tried a simple “set1 + set2”, and initially that looked like it worked, but it seems to result in the wrong result. With this, if set1 contains 2 objects, and set2 5 objects, I get the last 3 objects added to set1.

Ideally what I need is to combine them, and remove any duplicates. Each object in this set contains a set of user data (username, firstname, lastname).

Any thoughts would be welcome - I’m sure this should be simple, but I can’t see a way to do it…

Here you are:

Via UI:

Via a formatter/module and some custom code(if you are using js):

Thanks for the quick response, but I’m not sure this is what I need?

If I understand the link correctly, this is taking an array (or data set) from one source, and adding more information into this array from a second data source. What I need to do is take two data sources that are exactly the same and combine them.

Isn’t that the same thing?
You can filter what gets merged while looping in the repeat. So if the element already exists in the first one you don’t add it.

Maybe I don’t understand fully your request. If you could post an example that would help.

I don’t think so.

The does -:

{
  {
    "user": "Fred"
  }
}
+
{
  {
    "address": "1 Fred Drive"
  }
}
=
{
  {
    "user": "Fred"
    "address": "1 Fred Drive"
  }
}

What I want is

{
  {
    "user": "Fred"
  }
}
+
{
  {
    "user": "John"
  }
}
=
{
  {
    "user": "Fred"
  }
  {
    "user": "John"
  }
}

I want two records, with the same data and I want to join them. The example you provided takes one list, looping over the contents to perform a query on a different data set and adds that extra data.

I’ve not found a way to merge them though. As I said earlier, if I use a simple +, it doesn’t seem to combine the two arrays. For example, if set1 has {1,2,3} and set2 has {5,6,7,8}, when I use set1+set2 I get {1,2,3,8}.

1 Like

He also needs to remove duplicates so to complement that php custom formatter he will have to do something like array_unique(array_merge($array1,$array2), SORT_REGULAR);

That is if he is using PHP which he hasn’t mentioned.

I know what I would do now that we have custom modules and formatters :smiley:
Lodash for the save

1 Like

Ok, thanks guys. I can write a custom PHP module - it just seemed that this ought to be simple with the graphical editor and I’d assumed I was missing something obvious :sunglasses:

Yes, as I said, this is all server side, so I have PHP - no problem there :slight_smile:

1 Like

Great that you can progress. I meant that I didn’t know if this was php, asp or nodejs :slight_smile:

1 Like

Please check;

That’s already possible using the Server Connect Array List component:

This topic was automatically closed after 26 hours. New replies are no longer allowed.