Ash FrameworkAF
Ash Framework6mo ago
10 replies
Gonzalo Muñoz

Complex resource generation?

Hey guys, I'm getting a bit of chicken & egg problem when I try to create my resources using generators. As most of them are somehow related to one another, I get all sorts of compile time errors, no matter which ones I try to run first. How do you handle these situations yourselves? Is it at all possible to build my app using generators, or do I have to manually write most of them?

For example, a Subtitle belongs to a Video, and a Video has many Subtitles. Whenever I try to crate one, the othe must be already present, otherwise I get an error. Maybe I'm doing something wrong?

mix ash.gen.resource Susflix.Media.Video --uuid-primary-key id --relationship "has_many:subtitles:Susflix.Media.Subtitle"
mix ash.gen.resource Susflix.Media.Subtitle --uuid-primary-key id --relationship "belongs_to:video:Susflix.Media.Video"

Compiling 107 files (.ex)
warning: invalid association `subtitles` in schema Susflix.Media.Video: associated schema Susflix.Media.Subtitle does not exist
└─ lib/susflix/media/video.ex: Susflix.Media.Video (module)

** (EXIT from #PID<0.95.0>) an exception was raised:
    ** (RuntimeError) Relationship Susflix.Media.Video.subtitles has an invalid destination: Susflix.Media.Subtitle.

        lib/susflix/media.ex:1: Susflix.Media.__verify_spark_dsl__/1
        (elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
        (elixir 1.18.4) lib/module/parallel_checker.ex:244: Module.ParallelChecker.check_module/3
        (elixir 1.18.4) lib/module/parallel_checker.ex:90: anonymous fn/7 in Module.ParallelChecker.inner_spawn/6
Was this page helpful?