Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meta to all relations #1042

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

zaosoula
Copy link
Contributor

🔗 Linked issue

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Add the meta property to relations like on classic column to convey additional data for third party libraries

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@zaosoula zaosoula marked this pull request as ready for review July 19, 2024 06:42
@thetutlage
Copy link
Member

Hello @zaosoula

Can you please share what use-cases we are trying to serve by adding the meta property to relationships?

@zaosoula
Copy link
Contributor Author

@thetutlage
Hi, we use meta to define the options of editable field for the frontend, it allow use to automaticaly generate view, and forms based on the model

import { BaseModel, column, manyToMany } from '@adonisjs/lucid/orm'
import { compose } from '@adonisjs/core/helpers'
import { Filterable } from 'adonis-lucid-filter'
import ProductFilter from '#filters/product_filter'
import { CommonModel } from '#mixins/common_model'
import { EntityModel } from '#mixins/entity_model'
import User from '#models/user'
import ProductCategory from './product_category.js'
import type { ManyToMany } from '@adonisjs/lucid/types/relations'

export default class Product extends compose(
  BaseModel,
  Filterable,
  CommonModel({ userModel: User }),
  EntityModel({ userModel: User })
) {
  static $filter = () => ProductFilter

  @column({
    meta: {
      label: 'Nom',
      type: 'text',
      summary: true,
    },
  })
  declare name: string

  @column({
    meta: {
      label: 'Récurrent',
      type: 'checkbox',
      summary: true,
    },
  })
  declare isRecurrent: boolean

  @manyToMany(() => ProductCategory, {
    meta: {
      label: 'Catégories',
      type: 'autocomplete',
      options: {
        resource: 'product-category',
        label: 'name',
      },
      summary: true,
    },
  })
  declare categories: ManyToMany<typeof ProductCategory>
}

@thetutlage thetutlage merged commit ade635f into adonisjs:21.x Nov 18, 2024
16 checks passed
@thetutlage
Copy link
Member

Thanks 👍

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.

3 participants