Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Mykolas Mankevicius
Mykolas Mankevicius

Posted on

Ash - Create with relationship

Ok been stuck on this thing :D I have this resource:

defmoduleNoSpark.Builder.DindouseAsh.Resource,data_layer:AshSqlite.DataLayersqlitedotable"dins"repoNoSpark.Repoendattributesdouuid_primary_key:idattribute:label,:stringattribute:description,:stringattribute:slots,:integerdoallow_nil?falseconstraintsmin:0endendrelationshipsdobelongs_to:schema,NoSpark.Builder.Schemaendcode_interfacedodefine_for(NoSpark.Builder)define(:create)define(:read)define(:update)endactionsdodefaults[:create,:read,:update,:destroy]endend
Enter fullscreen modeExit fullscreen mode

And i want to create the din with a schema already attached.

All you really need to do is update the relationshipbelongs_to to make it writable:

belongs_to:schema,NoSpark.Builder.Schemadoattribute_writable?trueend
Enter fullscreen modeExit fullscreen mode

And now you can create your resource with the schema relationship attached like so:

Din.create!(%{label:"Din X",slots:schema.slots,schema_id:schema.id})
Enter fullscreen modeExit fullscreen mode

Whereschema is just some schema which is already created.

This took me a while to figure out :D Hope this helps you!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full stack developer. Working on making complex things as simple as i can make them.
  • Location
    Vilnius, Lithuania
  • Work
    Software developer at: marko.ch
  • Joined

More fromMykolas Mankevicius

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp