# Poco::ActiveRecord

# template < typename IDType >

# class ActiveRecord

Library: ActiveRecord
Package: ActiveRecord
Header: Poco/ActiveRecord/ActiveRecord.h

## Description

The base class for all database objects that implement the ActiveRecord pattern, with a single key column.

## Inheritance

Direct Base Classes: ActiveRecordBase

All Base Classes: ActiveRecordBase, Poco::RefCountedObject

## Member Summary

Member Functions: id, isValid, lastInsertID, mutableID, queryInto, toString, updateID, withContext

Inherited Functions: attach, context, create, detach, duplicate, insert, isAttached, isValid, referenceCount, release, remove, toString, update, withContext

## Types Aliases

### ID

using ID = IDType;

### Ptr

using Ptr = Poco::AutoPtr < ActiveRecord >;

## Constructors

### ActiveRecord

ActiveRecord() = default;

### ActiveRecord

ActiveRecord(
ID id
);

### ActiveRecord

ActiveRecord(
const ActiveRecord & other
);

## Destructor

### ~ActiveRecord

~ActiveRecord() = default;

## Member Functions

### id

ID id() const;

Returns the unique ID of the object.

### isValid

bool isValid() const;

See also: Poco::ActiveRecord::ActiveRecordBase::isValid()

### toString

std::string toString() const;

See also: Poco::ActiveRecord::ActiveRecordBase::toString()

### lastInsertID

static ID lastInsertID(
Poco::Data::Session & session
);

Returns the last inserted ID from the database session. Used for automatically incrementing keys.

### mutableID

ID & mutableID();

### queryInto

template < typename AR > static void queryInto(
Poco::Data::Statement & statement,
AR & ar
);

### updateID

void updateID(
Poco::Data::Session & session
);

Updates the ID using lastInsertID().

### withContext

template < typename T > static Poco::AutoPtr < T > withContext(
Poco::AutoPtr < T > pObj,
Context::Ptr pContext
);

## Variables

### INVALID_ID

static const IDType INVALID_ID;