Skip to content

Conversation

@lucianomasuelli
Copy link
Contributor

Field and Model Relationship Management Tools

This pull request introduces a comprehensive suite of tools for managing field extraction and relationship conversions in Slingr models. These tools provide developers with powerful refactoring capabilities to restructure their data models efficiently.

New Tools Added

Field Extraction Tools

Extract Fields to Parent (extractFieldsToParent.ts)

  • Workflow: Select multiple fields from a model → Create new abstract parent model → Move selected fields to parent → Update source model to extend the new parent
  • Use Case: Ideal for creating inheritance hierarchies and sharing common fields across multiple models

Extract Fields to Embedded (extractFieldsToEmbedded.ts)

  • Workflow: Select fields from model → Create new embedded model file → Move fields to embedded model → Add embedded field to source model → Remove original fields
  • Use Case: Perfect for grouping related fields into logical embedded components

Extract Fields to Reference (extractFieldsToReference.ts)

  • Workflow: Select fields → Create new independent model file → Move fields to new model → Add reference field to source model → Remove original fields
  • Use Case: Best for extracting fields that should exist as separate entities with their own lifecycle

Extract Fields to Composition (extractFieldsToComposition.ts)

  • Workflow: Select fields → Create component model within same file → Move fields to component → Add composition field → Remove original fields
  • Use Case: Great for creating tightly coupled components that don't need separate files

Relationship Conversion Tools

Change Reference to Composition (changeReferenceToComposition.ts)

  • Workflow: Identify reference field → Check if referenced model is used elsewhere → Convert to composition → Optionally delete unused referenced model file → Create component model in source file
  • Use Case: Converting loose relationships to tightly coupled components

Change Composition to Reference (changeCompositionToReference.ts)

  • Workflow: Identify composition field → Extract component model to separate file → Convert composition field to reference → Clean up unused enums and component model from source file
  • Use Case: Promoting component models to independent entities

Relationship Creation Tools

Add Reference (addReference.ts)

  • Workflow: Choose field name → Select existing model or create new model → Add reference field → Handle imports and file creation if needed
  • Use Case: Creating relationships to existing or new independent models

Add Composition (addComposition.ts)

  • Workflow: Enter field name → Auto-generate component model name → Create component model in same file → Add composition field
  • Use Case: Adding tightly coupled component relationships

Benefits

  • Improved Code Organization: Easily restructure models to follow better architectural patterns
  • Reduced Boilerplate: Automated field and model generation reduces manual coding
  • Safe Refactoring: Built-in validation prevents breaking existing relationships
  • Enhanced Developer Experience: Intuitive workflows with clear prompts and error handling

These tools significantly enhance the Slingr development experience by providing powerful model refactoring capabilities that maintain code quality and project integrity.

lucianomasuelli and others added 30 commits September 9, 2025 13:56
…xplorer when there are more than one models in the file.
…ontroller.

Adds multiple fields handling in the RefactorController.
Adds some code refactors and utility methods in addField.ts and addComposition.ts
… the creation of edit in every refactor command.
…pdated explorer to detect new 'Composition' decorators.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a comprehensive suite of tools for managing field extraction and relationship conversions in Slingr models. The tools provide developers with powerful refactoring capabilities to restructure their data models efficiently.

  • Field extraction tools for creating parent, embedded, reference, and composition models from existing fields
  • Relationship conversion tools for changing between reference and composition patterns
  • Enhanced relationship creation tools with new composition and reference capabilities

Reviewed Changes

Copilot reviewed 43 out of 44 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/test/ Updated test files to correct model inheritance, add comprehensive test coverage for new tools, and remove obsolete tests
src/services/ Enhanced source code service with model manipulation, enum handling, and datasource import capabilities
src/refactor/tools/ Added relationship conversion tools and updated existing tools with confirmation dialogs
src/commands/ Implemented new field extraction and relationship management commands with command helper abstractions
src/explorer/ Enhanced tree view with multi-selection support and better field type visualization
src/cache/ Added utility methods for model lookup and datasource filtering
Comments suppressed due to low confidence (2)

src/commands/fields/changeReferenceToComposition.ts:1

  • There's corrupted text in the success message. The line appears to have been corrupted during editing, with partial method signature mixed into the string literal.
import * as vscode from "vscode";

src/services/sourceCodeService.ts:1

  • The import path uses a hardcoded 'datasource' filename instead of using the actual dataSource name variable. This should be '../dataSources/${dataSource}' to correctly import the specific datasource.
import * as vscode from "vscode";

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 356 to 357
lines.push(`\t@Field({})`);
lines.push(`\t@Field({})`);
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing closing brace for the second @field decorator on line 357. This will result in invalid TypeScript syntax.

Suggested change
lines.push(`\t@Field({})`);
lines.push(`\t@Field({})`);

Copilot uses AI. Check for mistakes.
Comment on lines 408 to 409
lines.push(`\t@UUID()`);
lines.push(`\t@PrimaryKey()`);
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @field decorator for the id property. The UUID and PrimaryKey decorators should be applied to a field that also has the @field decorator.

Copilot uses AI. Check for mistakes.
@dgaviola
Copy link
Member

Let's adjust this so by default the ID of persistent models have this definition:

export class Test extends BaseModel {
  @Field({
    primaryKey: true
  })
  @UUID({
    generated: true
  })
  id!: string
}

@lucianomasuelli lucianomasuelli linked an issue Sep 24, 2025 that may be closed by this pull request
Gaviola pushed a commit that referenced this pull request Sep 26, 2025
[FEAT] [NO ISSUE] Add support for MySQL and PostgreSQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjust how we handle persistent models Relationships management

4 participants