Support #5153
openGet ID of a database object
0%
Description
How to get ID of database object? Below you see my query to the table. Result of this query is uest as a model for combobox. but now, how do i get the ID of a single autor so i could do query for arr the albums that belong to the Author. its a many-to-one relation.
@
AuthorsModel* Database::getAuthors() {
dbo::Transaction trans(session_);
AuthorsModel *model = new AuthorsModel();
model->setQuery(session_.find());
model->addColumn("name");
trans.commit();
return model;
}
AlbumsModel* Database::getAlbums(int author_id) {
dbo::Transaction trans(session_);
AlbumsModel* model = new AlbumsModel();
model->setQuery(session_.find().where("author_id = ?").bind(author_id));
model->addColumn("name");
trans.commit();
return model;
@
Updated by Koen Deforche almost 9 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
You can use QueryModel::resultRow().id()
Updated by Marko Taht almost 9 years ago
Ok. I got the Id but the query returns nothing. Author and Album are connected via ManyToOne relation. One author can have many albums. I need to get access to the albums of Author. Author.albums gives error, that i need a new transaction. And trying to query via author_id gives 0 results. So what am i doing wrong?