Deleting using ormlite on android?

后端 未结 2 1207
广开言路
广开言路 2021-02-07 05:07

I have a Client bean ,

@DatabaseField(columnName = \"client_id\",generatedId = true,useGetSet = true)
private Integer clientId;
@DatabaseField(columnName = \"cli         


        
2条回答
  •  故里飘歌
    2021-02-07 05:40

    ORMLite does not support cascading deletes @Majid. That is currently outside of what it considers to be "lite". If you delete the city then you need to delete the clients by hand.

    One way to ensure this would be to have a CityDao class that overrides the delete() method and issues the delete through the ClientDao at the same time. Something like:

    public class CityDao extends BaseDaoImpl {
        private ClientDao clientDao;
        public CityDao(ConnectionSource cs, ClientDao clientDao) {
            super(cs, City.class);
            this.clientDao = clientDao;
        }
        ...
        @Override
        public int delete(City city) {
            // first delete the clients that match the city's id
            DeleteBuilder db = clientDao.deleteBuilder();
            db.where().eq("city_id", city.getId());
            clientDao.delete(db.prepare());
            // then call the super to delete the city
            return super.delete(city);
        }
        ...
    }
    

提交回复
热议问题