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

Add collection option for resource relations #2084

Merged

Conversation

robinboening
Copy link
Contributor

This addition allows to provide a scoped collection of records when defining a resource relation.

Example:

class Event < ApplicationRecord
  belongs_to :location

  def self.alchemy_resource_relations
    {
      location: {
        attr_method: "name",
        attr_type: "string",
        collection: Location.where(...)
      },
    }
  end
end

In the view the user will see the scoped collection of locations in the select box.

In case collection is not passed

  • Location.all will be used
  • class_name on the association is used if it's defined

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

this addition allows to provide a scoped collection of records when defining a resource relation.

Example:

```
class Event < ApplicationRecord
  belongs_to :location

  def self.alchemy_resource_relations
    {
      location: {
        attr_method: "name",
        attr_type: "string",
        collection: Location.where(...)
      },
    }
  end
end
```

In the view the user will see the scoped collection of locations in the select box.

In case `collection` is not passed

  * `Location.all` will be used
  * `class_name` on the association is used if it's defined
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Very nice! Thank you

@tvdeyen tvdeyen added this to the 6.0 milestone May 5, 2021
@tvdeyen tvdeyen merged commit 32eab15 into AlchemyCMS:main May 6, 2021
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.

2 participants