Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving joining of RecordSets #1446

Open
bowdi opened this issue Feb 14, 2025 · 2 comments
Open

Improving joining of RecordSets #1446

bowdi opened this issue Feb 14, 2025 · 2 comments

Comments

@bowdi
Copy link

bowdi commented Feb 14, 2025

Describe the problem to be solved

Refs:

I've got a table similar to what is described in community #1495 , although in my scenario, I have the following schema:

Objectives

  • type - choice e.g. project, task
  • title - text field
  • parent - a self reference to the objectives table
    as formula reference lists aren't supported as two way references these are included:
  • links_from - a two way reference list
  • links_to - the other two way reference list

Links

  • from - reference field to objectives
  • link - text explaining the link
  • to - reference field to objectives
  • links - a formula reference list joining the $from and $to fields as described in the community post

I have one use case that requires two joins, I'd like a reference list on Objectives that includes links of itself AND links of it's parent (chain). I would need to join links_from and links_to into a single reference list $links on Objectives first then join $parent.links and $links into $all_links together.

This is possible with nested list comprehension but it's not intuitive and could be simpler!

Describe the solution you would like

Overriding the __add__ operator in python record.RecordSet might work and it would result in formula like this:

  • $links: $links_to + $links_from
  • $all_links: $parent.links + $links

rather than this:

  • $links: { el for sublist in [$links_to, $links_from] for el in sublist }
  • $all_links: { el for sublist in [$parent.all_links, $links] for el in sublist }
@dsagal
Copy link
Member

dsagal commented Feb 16, 2025

A couple of notes here:

One is that in addition to the list-comprehension approach, you can also use set($links_to) | set($links_from) (when you want to remove any duplicates and order doesn't natter) or list($links_to) + list($links_from (when you want to keep duplicates and order).

The other note is that a there was an improvement last year to a related issue reported here: #1130. If adding an __add__ operator, it would make sense to match that behavior (which takes care of preserving order, but removing duplicates, see here).

@bowdi
Copy link
Author

bowdi commented Feb 17, 2025

Oh nice! Thanks for those tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants