Git Product home page Git Product logo

Comments (6)

zachdaniel avatar zachdaniel commented on May 31, 2024 1

So you can achieve it with a custom type, i.e

defmodule MyApp.Types.Report do
  use Ash.Type
  
  def cast_input(%{type: type} = input, _) do
    resource = case type do
       :category -> MyApp.ReportTypes.Category
       ...
    end
    
        resource |> Ash.Changeset.for_create(:create, input) |> MyApp.Api.create()
  end

  def cast_stored(%{"type" => type}, _) do
        resource = case type do
          ...
        end
        
         resource |> Ash.Changeset.for_create(:create, input) |> MyApp.Api.create()
  end
  
 ..
end

Since technically in Ash embeds are really just types under the hood, you can do pretty much anything they do and have a polymorphic result. At some point, union types will likely be added to core to accomplish this.

from ash_postgres.

zachdaniel avatar zachdaniel commented on May 31, 2024 1

Realistically, a custom type could be made that abstracts this generically. i.e

attribute :reports, {:array, MyApp.Types.PolymorphicEmbed} do
  constraints [items: [types: [foo: Foo, bar: Bar]]]
end

from ash_postgres.

tommasop avatar tommasop commented on May 31, 2024

@zachdaniel thanks for your super quick reply, this will allow us to proceed with prototyping.

from ash_postgres.

zachdaniel avatar zachdaniel commented on May 31, 2024

My pleasure :) Let me know if you have any other questions :) Feel free to join the discord as well.

from ash_postgres.

tommasop avatar tommasop commented on May 31, 2024

I tried to sign up to discord but was immediately disabled as a user (without logging in a single time) I'm trying to solve the issue with their support but it's taking longer than expected :(

from ash_postgres.

zachdaniel avatar zachdaniel commented on May 31, 2024

oh no :( Well if you're in the elixir discord, you can reach me through the #ash-framework channel. Sorry that happened! Hopefully not happening to others trying to join the discord as well...

from ash_postgres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.