Code Monkey home page Code Monkey logo

Comments (7)

RingoD avatar RingoD commented on May 18, 2024 1

麻烦详细描述需求,如何一对多、多对多等

from wcdb.

qingyunhe avatar qingyunhe commented on May 18, 2024 1

复杂的表结构交给后台处理吧

from wcdb.

312362115 avatar 312362115 commented on May 18, 2024

比如Teacher class 和 Student class

一个 Teacher可能有多个Student
每个Student可能有多个Teacher

在创建模型的时候, 大概是:

@interface Teacher : NSObject

@property (nonatomic, copy) NSString *tid;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSArray<Student *> *students;

@end


@interface Student : NSObject

@property (nonatomic, copy) NSString *sid;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSArray<Teacher *> *teachers;

@end

用WCDB怎么创建各自的表和关系表呢,
CRUD怎么操作呢

from wcdb.

RingoD avatar RingoD commented on May 18, 2024

ORM没有纳入关系表。
如果你是希望保证students和teachers数据的对应关系,可以将其定义为BLOB类型,然后用transaction保证数据准确。

[database runTransaction:^BOOL{
    Student* student = [[Student alloc] init] ;
    student.name = @"newStudent";
    Teacher* teacher = [[Teacher alloc] init] ;
    teacher.name = @"newTeacher";
    [teacher.students addObject:student]
    [student.teachers addObject:teacher];
    return [database insertOrReplaceObject:student into:@"students"]
            &&[database insertOrReplaceObject:teacher into:@"teachers"];
}];

或者用trigger应该也可以。WCDB没有提供trigger的方便接口,可以使用 Core 接口,配合WINQ来实现。

正如 qingyunhe 所说,不建议在客户端使用复杂的表结构。

from wcdb.

chenyunecjtu avatar chenyunecjtu commented on May 18, 2024

android 是否可以提供一下orm

from wcdb.

RingoD avatar RingoD commented on May 18, 2024

@chenyunecjtu 这个问题不是讨论Android ORM,麻烦你新开一个Issue

from wcdb.

RingoD avatar RingoD commented on May 18, 2024

no reply

from wcdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.