# Add ability to specify specific struct class for auto\_struct

**URL:** <https://discourse.rom-rb.org/t/add-ability-to-specify-specific-struct-class-for-auto-struct/312>\
**Category:** Issues\
**Created:** [April 20, 2019, 10:25pm UTC](https://discourse.rom-rb.org/t/add-ability-to-specify-specific-struct-class-for-auto-struct/312 "2019-04-20T22:25:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [April 20, 2019, 10:25pm UTC](https://discourse.rom-rb.org/t/add-ability-to-specify-specific-struct-class-for-auto-struct/312/1 "2019-04-20T22:25:28Z")

</div>

An issue that has come up fairly regularly for us is that structs will map to an unintended classes when using auto\_struct. One such case in when an association is aliased. Something like

```ruby
# we want it to map to this
class PostCategory
end

class Post < ROM::Relation[:posts]
  schema do
    associations do
      has_one :post_category, as: :category
    end
  end
end

# the hacky fix
Category = PostCategory

```

What do you think about offering an option like: `entity_implementation PostCategory`? I think this would be much more predictable and won’t fail in confusing ways. Thoughts?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [April 22, 2019, 9:55am UTC](https://discourse.rom-rb.org/t/add-ability-to-specify-specific-struct-class-for-auto-struct/312/2 "2019-04-22T09:55:29Z")

</div>

hey @ianks! We have a similar thread over here [Aliased association doesn't map to the entity of the relation](https://discourse.rom-rb.org/t/aliased-association-doesnt-map-to-the-entity-of-the-relation/283/4) please chime in there. We could add this feature in `5.1.0` because we’re wrapping up `5.0.0` this week.

---

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [May 25, 2019, 5:45am UTC](https://discourse.rom-rb.org/t/add-ability-to-specify-specific-struct-class-for-auto-struct/312/3 "2019-05-25T05:45:12Z")

</div>

Sorry for the late reply, busy these last few weeks.

After thinking about this a little more, I think we definitely should add a way to ensure a proper struct/entity is generated. I see two options:

1. Specify the exact `class` that should be inherited from when building the struct class.

2. And/or specify the _behavior_ the resulting struct should have by allowing modules to be included when building the class.

So something like:

```
class Product < ROM::Relation[:sql]
  decorate(
    AttachedFile[:warranty],
    Reviewable,
    Categorizable
  )
  # ...
end

```

This would be nice because it makes it much less tedious to setup commonly used data access methods, without having to drop into another file/etc. I often find myself hopping around to do this when all I really need is some simple behavior.

I think having the ability to do both 1 and 2 would be a huge win 🙂
