Project

General

Profile

Actions

Support #5153

open

Get ID of a database object

Added by Marko Taht over 7 years ago. Updated over 7 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;

@

Actions #1

Updated by Koen Deforche over 7 years ago

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

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

Actions #2

Updated by Marko Taht over 7 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?

Actions

Also available in: Atom PDF