简体   繁体   中英

Filtered REALM with React Native

I want to search for certain data in a range of one year, and I am not taking this range and I put directly the variable yearLive of the Predicate error.

but all members of each family are returning and not just one year old children.

obterCriancaUmAno = familia_uuid => {
    const now = moment().format('YYYY-MM-DDT00:00:00');
    const oneYearAgo = moment()
      .subtract(1, 'year')
      .format('YYYY-MM-DDT00:00:00');

    let yearLive = ` AND BEGINSWITH birth_date = ${oneYearAgo} AND ENDSWITH birth_date = ${now}`;

    return new Promise(async (resolve, reject) => {
      const realm = await getRealm();
      try {
        let families = Array.from(
          realm
            .objects('Family')
            .filtered(
              `familia_uuid = "${family_uuid}" AND ativo = true AND saida_cadastro = null`,
              yearLive,
            ),
        );

        resolve(families);
      } catch (error) {
        reject(error);
      }
    });
  };

this was the solution I found for my problem

obterTodosMembrosFamiliaUmAno = () => {
const now = moment().format('YYYY-MM-DD');
const oneYearAgo = moment()
  .subtract(1, 'year')
  .format('YYYY-MM-DD');

return new Promise(async (resolve, reject) => {
  const realm = await getRealm();
  try {
    let Membros = realm
      .objects('MembroFamilia')
      .filtered(`ativo = true AND saida_cadastro = null `);

    //filter childrens
    let listMembros = await Membros.filter(function(a) {
      return a.data_nascimento >= oneYearAgo && a.data_nascimento < now;
    });

    resolve(listMembros);
  } catch (error) {
    reject(error);
  }
});

};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM