Skip to content

Commit

Permalink
Undeprecate :class_name (#2697)
Browse files Browse the repository at this point in the history
We tried to remove `:class_name` (along with some others), as it didn't
seem like they had a legitimate use as of #2384 and #2546. But we've
been seeing various cases where it's still helpful to have.

Closes #2384.
  • Loading branch information
pablobm authored Nov 4, 2024
1 parent a4a2afa commit f9c5f1a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 34 deletions.
10 changes: 5 additions & 5 deletions docs/customizing_dashboards.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ For example:
with this, you will be able to search through the column `name` from the
association `belongs_to :country`, from your model.

`:class_name` - Specifies the name of the associated class.

`:primary_key` (deprecated) - Specifies the association's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasMany**

`:collection_attributes` - Set the columns to display in the show view.
Expand All @@ -124,12 +124,12 @@ set this to `0` or `false`. Default is `5`.

`:direction` - What direction the sort should be in, `:asc` (default) or `:desc`.

`:class_name` - Specifies the name of the associated class.

`:primary_key` (deprecated) - Specifies object's primary_key.

`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.

`:class_name` (deprecated) - Specifies the name of the associated class.

**Field::HasOne**

`:order` - Specifies the column used to order the records. It will apply both in
Expand All @@ -154,7 +154,7 @@ For example:
with this, you will be able to search through the column `name` from the
association `has_one :city`, from your model.

`:class_name` (deprecated) - Specifies the name of the associated class.
`:class_name` - Specifies the name of the associated class.

**Field::Number**

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/scoping_has_many_relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Since ActiveRecord infers the class name from the first argument, the new `has_m

## Add new relationship to dashboard

Your new scoped relation can be used in the dashboard just like the original `HasMany`. Notice the new field needs to specifiy the class name as an option like you did in the model.
Your new scoped relation can be used in the dashboard just like the original `HasMany`.

```ruby
ATTRIBUTE_TYPES = {
orders: Field::HasMany,
processed_orders: Field::HasMany.with_options(class_name: 'Order')
processed_orders: Field::HasMany
```
2 changes: 1 addition & 1 deletion lib/administrate/field/associative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def associated_class

def associated_class_name
if option_given?(:class_name)
deprecated_option(:class_name)
options.fetch(:class_name)
else
self.class.associated_class_name(
resource.class,
Expand Down
16 changes: 0 additions & 16 deletions spec/lib/fields/belongs_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@
/^Line Item \#\d\d\d\d$/
)
end

it "triggers a deprecation warning" do
line_item = create(:line_item)
field_class = Administrate::Field::BelongsTo.with_options(
class_name: "Customer"
)
field = field_class.new(
:product,
line_item.product,
:show,
resource: line_item
)
field.associated_class
expect(Administrate.deprecator).to have_received(:warn)
.with(/:class_name is deprecated/)
end
end

describe ":include_blank option" do
Expand Down
10 changes: 0 additions & 10 deletions spec/lib/fields/has_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@
expect(dashboard_double).to have_received(:collection_attributes)
expect(attributes).to eq([])
end

it "triggers a deprecation warning" do
association = Administrate::Field::HasMany
.with_options(class_name: "Foo")
field = association.new(:customers, [], :show)
field.associated_collection

expect(Administrate.deprecator).to have_received(:warn)
.with(/:class_name is deprecated/)
end
end

describe "primary_key option" do
Expand Down

0 comments on commit f9c5f1a

Please sign in to comment.