Skip to content

[Model] Add missing relationships, query scopes, and factory states #53

@ibourgeois

Description

@ibourgeois

Problems

  • User model is missing a projects() HasMany relationship despite projects.user_id FK existing
  • Idea model has no shared()/draft() scopes despite a DB index on (user_id, shared_at) designed to support this pattern
  • Project model has no proposed() scope despite a DB index on (idea_id, status)
  • UserFactory doesn't include the theme_preferences column (added via migration)
  • IdeaFactory has no shared() state, making it hard to test any sharing logic

Required Changes

  • User: add public function projects(): HasMany returning $this->hasMany(Project::class)
  • Idea: add scopeShared() (whereNotNull('shared_at')) and scopeDraft() (whereNull('shared_at'))
  • Project: add scopeProposed() (where('status', 'proposed'))
  • UserFactory: include theme_preferences with a default value of ['mode' => 'system']
  • IdeaFactory: add shared() state that sets shared_at to now()

Files

  • app/Models/User.php
  • app/Models/Idea.php
  • app/Models/Project.php
  • database/factories/UserFactory.php
  • database/factories/IdeaFactory.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions