yangfuhai / afinal

Afinal是一个android的ioc,orm框架,内置了四大模块功能:FinalAcitivity,FinalBitmap,FinalDb,FinalHttp。通过finalActivity,我们可以通过注解的方式进行绑定ui和事件。通过finalBitmap,我们可以方便的加载bitmap图片,而无需考虑oom等问题。通过finalDB模块,我们一行代码就可以对android的sqlite数据库进行增删改查。通过FinalHttp模块,我们可以以ajax形式请求http数据。详情请通过以下网址查看。
3.16k stars 1.49k forks source link

修复FinalDb OneToMany无效的问题 #46

Closed fantouch closed 11 years ago

fantouch commented 11 years ago

修复FinalDb.loadOneToMany(T entity, Class<T> clazz, Class<?>... findClass)方法无效的问题,
顺带修复OneToMany懒加载中Parent.getChildren().getList().size()总为0的问题.

rtspVideoview commented 9 years ago

为什么我还是有Parent.getChildren().getList().size()总为0的问题呢?

rtspVideoview commented 9 years ago
代码如下:    
    Parent parent = new Parent();   
    parent.setName("臭臭");
    parent.setId(22);

    Child child1 = new Child();     
    child1.setName("满宝臭臭");
    child1.setParent(parent);

    Child child2 = new Child();     
    child2.setName("满宝笨笨");
    child1.setParent(parent);

    List<Child> value = new ArrayList<Child>();
    value.add(child1);
    value.add(child2);

    OneToManyLazyLoader<Parent, Child> children = new OneToManyLazyLoader<Parent, Child>(parent, Parent.class, Child.class, db);
    children.setList(value);
    parent.setChildren(children);

    db.save(parent);//删除表后出错
    db.save(child1);
    db.save(child2);

    List<Parent> all = db.findAll(Parent.class);
    for( Parent  item : all){
        if(item.getChildren ().getList().size()>0)
            System.out.println(item.getName() + item.getChildren().getList().get(0).getName());   
        else
        {
            System.out.println("------------------失败--------------------");
            System.out.println(item.getChildren ().getList().size());
        }
    }