Skip to content

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 👍

nadlgit pushed a commit to nadlgit/adonisjs-lucid that referenced this pull request Jun 28, 2025
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