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

Querying table with has_many relation length not null #1805

Open
KevinBrustolin opened this issue Jun 11, 2024 · 0 comments
Open

Querying table with has_many relation length not null #1805

KevinBrustolin opened this issue Jun 11, 2024 · 0 comments

Comments

@KevinBrustolin
Copy link

Hello,

I'm looking for a way to query a table where the length of the children (has_many relation) is greater than 0.

I'm currently doing it like this:

  const disciplines = useLstObservable({
    table: 'param_discipline',
  });
  const [filteredDisciplines, setFilteredDiscipline] = useState([]);
  useEffect(() => {
    const getFilteredDisciplines = async () => {
      const filteredDisciplines = [];
      for (const discipline of disciplines) {
        const count = await discipline.epreuves.count;
        if (!!count) {
          filteredDisciplines(discipline);
        }
      }
      return filteredDisciplines;
    };
    getFilteredDisciplines().then(setFilteredDiscipline);
  }, [disciplines]);

Is there a better way ?

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

1 participant