Project

General

Profile

Actions

Support #5153

open
MT KD

Get ID of a database object

Support #5153: Get ID of a database object

Added by Marko Taht about 10 years ago. Updated about 10 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
Target version:
-
Start date:
08/01/2016
Due date:
% Done:

0%

Estimated time:

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;
@

KD Updated by Koen Deforche about 10 years ago Actions #1

  • Status changed from New to Feedback
  • Assignee set to Koen Deforche

You can use QueryModel::resultRow().id()

MT Updated by Marko Taht about 10 years ago Actions #2

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?

Actions

Also available in: PDF Atom