My database consists of a table of items and a table of associated ads.
I would like my elm app to display either an item with its associated ads, or an ad with information on the parent item.
To match those interface needs, I would have liked to write the following two modules in elm, matching what my API already sends :
module Item.Model exposing (..)
import Ad.Model exposing (Ad)
type alias Item =
{ ads : Maybe List Ad
}
and
module Ad.Model exposing (..)
import Item.Model exposing (Item)
type alias Ad =
{ item : Maybe Item
}
This definition however results in the following dependencies cycle error :
ERROR in ./elm-admin/Main.elm
Module build failed: Error: Compiler process exited with error Compilation failed
Your dependencies form a cycle:
┌─────┐
│ Item.Model
│ ↓
│ Ad.Model
└─────┘
You may need to move some values to a new module to get rid of the cycle.
at ChildProcess.<anonymous> (/opt/app/assets/node_modules/node-elm-compiler/index.js:141:27)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Socket.<anonymous> (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:497:12)
@ ./js/admin.js 3:12-44
It looks like defining both type alias
in the same module doesn't make the compiler stop, but this is not a satisfying solution to me because I don't want every Model
of my app to end up in the same file.
Is there a way solve this without defining the two type aliases Ad
and Item
in the same module ?