bknd-define-relationship_skill

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.

2

GitHub Stars

1

Bundled Files

3 weeks ago

Catalog Refreshed

2 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstart where the catalogue uses aiagentskills.

npx veilstart add skill cameronapak/bknd-skills --skill bknd-define-relationship

  • SKILL.md11.5 KB

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.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
bknd-define-relationship skill by cameronapak/bknd-skills | VeilStrat