Core
Core Concepts
This section covers the core concepts and components of RhoSocial ActiveRecord. We'll use a consistent set of examples throughout to demonstrate how these concepts work together.
Example Domain Models
Throughout this documentation, we'll use two main example scenarios:
Social Media Application
User
├── id: int
├── username: str
├── email: str
├── created_at: datetime
├── posts: HasMany[Post]
└── comments: HasMany[Comment]
Post
├── id: int
├── user_id: int
├── content: str
├── created_at: datetime
├── author: BelongsTo[User]
└── comments: HasMany[Comment]
Comment
├── id: int
├── post_id: int
├── user_id: int
├── content: str
├── created_at: datetime
├── author: BelongsTo[User]
└── post: BelongsTo[Post]
E-Commerce System
User
├── id: int
├── email: str
├── name: str
└── orders: HasMany[Order]
Order
├── id: int
├── user_id: int
├── total: Decimal
├── status: str
├── created_at: datetime
├── user: BelongsTo[User]
└── items: HasMany[OrderItem]
Product
├── id: int
├── name: str
├── price: Decimal
├── stock: int
└── order_items: HasMany[OrderItem]
OrderItem
├── id: int
├── order_id: int
├── product_id: int
├── quantity: int
├── price: Decimal
├── order: BelongsTo[Order]
└── product: BelongsTo[Product]
Core Components
Models
Model definition and structure
Field types and validation
Model lifecycle events
Inheritance and mixins
Fields
Built-in field types
Custom field types
Field validation
Field options and constraints
Relationships
One-to-one (HasOne/BelongsTo)
One-to-many (HasMany)
Eager loading
Relationship queries
Querying
Basic CRUD operations
Query building
Conditions and filters
Sorting and pagination
Eager loading in queries
Transactions
Transaction management
Savepoints
Nested transactions
Error handling
Organization
The core documentation is organized as follows:
Models: Understanding model definition and behavior
Fields: Working with different field types
Field Mixins: Using pre-built field combinations
Field Validation: Implementing validation rules
Custom Fields: Creating custom field types
Relationships: Managing model relationships
Basic Operations: Core CRUD operations
Querying: Advanced query building
Key Concepts
Active Record Pattern
The Active Record pattern wraps database operations in object-oriented classes:
Each class corresponds to a table
Each instance corresponds to a row
Properties map to columns
Type Safety
RhoSocial ActiveRecord uses Pydantic for type safety:
Type checking at runtime
IDE support through type hints
Validation during data assignment
Data Consistency
The library ensures data consistency through:
Transaction support
Validation rules
Event hooks
Relationship integrity
Next Steps
Start with Models to understand the foundation
Explore Fields to learn about data types
Study Relationships for model connections
Master Querying for data retrieval
Each section includes practical examples using our social media and e-commerce scenarios to demonstrate concepts in real-world contexts.
Last updated