Models

A model represents one database table. It carries metadata (table name, primary key, columns) and inherits query-builder methods from ORM::OModel.

BaseModel

Place your models under app/models/. A minimal model:

// app/models/Post.h
#pragma once
#include "orm/omodel.h"

class Post : public ORM::OModel
{
public:
    Post() {
        table          = "posts";
        primaryKey     = "id";
        public_columns  = {"id", "title", "body", "user_id", "created_at"};
        private_columns = {};
    }
};

Relations

Builder exposes four relation helpers that OModel inherits:

  • hasOne(model, foreignKey, localKey)
  • hasMany(model, foreignKey, ownerKey)
  • belongsTo(model, foreignKey, ownerKey)
  • belongsToMany(model, pivotTable, foreignKey, ownerKey)

Each one schedules a join that gets resolved when you call get(). They mirror the relation API you may know from Laravel.

User u;
auto posts = u.find(42).hasMany(Post{}, "user_id", "id").get();