Ecto and Legacy Entity Attribute Value (EAV) Model

I’m trying to map a legacy application that currently uses an EAV model, in this scenario the entity table only has a unique idea a couple of key fields like status and everything else like name, title, description, price if it was a production is spread across multiple tables.

For example one of the tables I’m operating with entity_attribute_varchar has the following structure:

  • id
  • attribute_id
  • entity_id
  • value

There is one table for each potential value like integer, varchar, text and datetime; I’m struggling with mapping the data from all those tables into my main model / schema.

Any advice or ideas greatly welcomed.

1 Like

can you provide some simple code of what you are trying to do, and what is not working… (simple data structure and what you expect the data output to be)

sounds to me like you want to do joins… also it might be helpful if you have the sql from the legacy app and then replicate that behaviour in ecto…

remember - “model” is a bit dead in ecto land, so it’s schema - and then a context that loads in the data you want…

1 Like