Adding embedded resource attributes

Gooday,
I am trying to implement an embedded resource on ash 3.5.6 and getting a “runtime” error.
I am following the instructions for embedding a resource at - https://hexdocs.pm/ash/embedded-resources.html#adding-embedded-resource-attributes
I have tried both the following attribute definition and the array version but get the same error.
This seems to be an issue with the resource not being defined as a type?

‘’’ attribute :items, Items.Item, public?: true
attribute :sundries, Sundries.Sundry, public?: true ‘’’

‘’’ ** (RuntimeError) Dovetail.Items.Item is not a valid type.

Valid types include any custom types, or the following short codes (alongside the types they map to):

:map → Ash.Type.Map
:keyword → Ash.Type.Keyword
:term → Ash.Type.Term
:atom → Ash.Type.Atom
:string → Ash.Type.String
:integer → Ash.Type.Integer
:file → Ash.Type.File
:float → Ash.Type.Float
:duration_name → Ash.Type.DurationName
:function → Ash.Type.Function
:boolean → Ash.Type.Boolean
:struct → Ash.Type.Struct
:uuid → Ash.Type.UUID
:uuid_v7 → Ash.Type.UUIDv7
:binary → Ash.Type.Binary
:date → Ash.Type.Date
:time → Ash.Type.Time
:decimal → Ash.Type.Decimal
:ci_string → Ash.Type.CiString
:naive_datetime → Ash.Type.NaiveDatetime
:utc_datetime → Ash.Type.UtcDatetime
:utc_datetime_usec → Ash.Type.UtcDatetimeUsec
:datetime → Ash.Type.DateTime
:url_encoded_binary → Ash.Type.UrlEncodedBinary
:union → Ash.Type.Union
:module → Ash.Type.Module
:vector → Ash.Type.Vector

(ash 3.5.6) lib/ash/type/type.ex:753: Ash.Type.get_type!/1
(ash 3.5.6) lib/ash/type/type.ex:2199: Ash.Type.set_type_transformation/1
(spark 2.2.52) lib/spark/dsl/entity.ex:273: Spark.Dsl.Entity.build/3
(ash 3.5.6) /home/admin_ubuntu/quotechain/deps/spark/lib/spark/dsl/extension.ex:1171: Ash.Resource.Dsl.Attributes.Attribute.__build__/3
(spark 2.2.52) lib/spark/dsl/extension/entity.ex:91: Spark.Dsl.Extension.Entity.handle/6
lib/dovetail/quotes/quote.ex:98: (module)

‘’’

Do you have the embedded data layer on the inner type?

The attributes are Items and Sundries in the quote resource.

First of all, the module name in item.ex in the items directory is “Dovetail.Item” instead of “Items.Item”, and the module name in sundry.ex in the sundries directory is “Dovetail.Sundry” instead of “Sundries.Sundry”.

Secondly, the “domain: Dovetail.Quotes,” in item.ex and sundry.ex should be removed for an embedded resource.

I renamed as you suggested.
However, the error persisted until i put all the files under the dovetail folder.

I have this on the resource - quote.

‘’’ data_layer: AshPostgres.DataLayer ‘’’

The file location only matters in one scenario which is that embedded resources and types can’t be defined in the same file as resources

1 Like

thanks Zach