cameronapak/bknd-skills
Overview
This skill helps you define relationships between Bknd entities: many-to-one, one-to-one, many-to-many, and self-referencing hierarchies. It covers both UI and code workflows, junction table options, mappedBy/inversedBy naming, and patterns for querying and updating relations. Use it to create reliable foreign keys, inverse navigation, and join-ready schemas.
How this skill works
In UI mode you add a Relation field on the child entity, pick the target entity and relationship type, name the field, then save and sync the database. In code mode you declare relations in the second argument to em(), using relation(entity).manyToOne/oneToOne/manyToMany and options like mappedBy, inversedBy, connectionTable, and extra junction fields. The skill also shows direct foreign-key .references() for simple FKs and common query/update patterns (with/join, $attach/$detach/$set).
When to use it
- Creating parent/child links (posts → users) or exclusive pairings (user → profile)
- Modeling many-to-many sets with optional extra fields (posts ↔ tags, order_items)
- Building hierarchical self-references (categories → parent/children)
- Prototyping quickly via the UI or keeping reproducible schemas in code
- When you need custom FK names or junction table names (mappedBy, connectionTable)
Best practices
- Use plural entity names (users, posts) to avoid "Entity not found" errors
- Define relations inside the second argument to em() for code-mode schemas
- Prefer mappedBy for semantic FK fields (author → author_id) and inversedBy for navigation backrefs
- Use UI for quick prototyping and code mode for version control and team workflows
- Avoid manually creating FK fields when using relation(); use .references() only for simple FKs without navigation
Example use cases
- Blog: posts many-to-one users (author) and many-to-many tags with auto junction table
- E-commerce: orders many-to-one customers and many-to-many products using order_items with quantity/unit_price
- Nested categories: categories many-to-one categories with mappedBy parent and inversedBy children
- Auth/profile: users one-to-one profiles for exclusive user data
- Data migrations: switch to code mode to keep relations in version control and apply consistent schema changes
FAQ
Use .references() on a number field when you only need a foreign key column without inverse navigation or many-to-many support. Use relation() when you want model navigation, joins, or junction tables.
How do I avoid FK name conflicts like users_id already exists?
Set mappedBy to a different name (e.g., mappedBy: "author") so the generated FK becomes author_id instead of users_id.
26 skills
This skill helps you define and configure entity relationships in BKND, supporting many-to-one, one-to-one, many-to-many, and self-referencing links.
This skill helps you seed a Bknd database with initial, test, and dev data using code-first, idempotent patterns.
This skill helps you discover and map Bknd's auto-generated REST endpoints, routes, and SDK methods for faster integration.
This skill guides deploying a Bknd app to Cloudflare, Vercel, Docker, Node, and serverless platforms with production-ready defaults.
This skill helps you manage environment variables for Bknd projects, guiding .env creation, secrets handling, and platform-specific configuration across dev
This skill helps you create records in Bknd using SDK or REST, including relations, responses, errors, and bulk operations.
This skill helps you create new entities in Bknd, offering UI and code-mode workflows with type-safe definitions.
This skill helps configure storage backends for Bknd's media module across s3, cloudinary, local, and r2 adapters, with environment-aware setups.
This skill helps manage user sessions in Bknd apps by coordinating JWT lifecycles, storage, renewal, and invalidation.
This skill helps you diagnose and fix bknd errors quickly by error code, symptom, or common pattern.
This skill helps you query and retrieve data from Bknd entities using readOne, readMany, and readOneBy with filtering, sorting, and relation loading.
This skill helps you add fields to Bknd entities via UI or code, ensuring type safety, validation, and consistent schema evolution.
This skill helps you prepare a BKND app for production by configuring production mode, JWT security, guards, CORS, media storage, and deployment readiness.
This skill helps you initialize and configure Bknd authentication, including JWT, cookies, and roles for secure production-ready apps.
This skill helps you implement robust offset-based pagination with page calculations, metadata, and React integration patterns for BKND data.
This skill helps you create new Bknd user accounts programmatically or via UI, handling seed, registration, and role assignment.
This skill streamlines updating Bknd records via SDK or REST, supporting single, bulk, and relational updates with safe, structured responses.
This skill helps you configure fine-grained permissions for roles in Bknd, including simple strings, extended formats, policies, and entity-specific rules.
This skill helps you upload files to Bknd storage using SDK or REST, with entity attachments and progress tracking.
This skill guides configuring and validating user self-registration in Bknd apps, simplifying forms, validation, roles, and error handling for smooth
This skill helps you manage Bknd schema changes safely by guiding non-destructive edits, migrations, and synced deployment strategies.
This skill helps you configure and integrate OAuth providers (Google, GitHub, and custom) in Bknd by guiding setup, env vars, and frontend flow.
This skill helps you define and manage Bknd authorization roles, including permissions, defaults, and hierarchies, for secure, scalable access control.
This skill helps you provision and configure a production database for your Bknd app across SQLite, LibSQL, Cloudflare D1, PostgreSQL, Neon, Supabase, and Xata.
This skill guides you through setting up a local bknd project, including CLI, config, runtime, and dev server options.
This skill helps you write and run unit and integration tests for Bknd apps using in-memory databases, test helpers, and mocks.