Git Product home page Git Product logo

ecto_nested_changeset's Introduction

CI Hex Coverage Status

EctoNestedChangeset

This is a package for manipulating nested Ecto changesets.

Installation

Add ecto_nested_changeset to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_nested_changeset, "~> 0.2.1"}
  ]
end

Usage

The primary use case of this library is the manipulation of Ecto changesets used as a source for dynamic, nested forms in Phoenix LiveView.

category = %Category{
  posts: [
    %Post{
      id: 1,
      comments: [
        %Comment{body: "potato", id: 1},
        %Comment{body: "you", id: 2}
      ],
      title: "must"
    },
    %Post{comments: [], id: 2, title: "young"}
  ]
}

category
|> Ecto.Changeset.change()
|> append_at(:posts, %Post{title: "Padawan", comments: []})
|> prepend_at([:posts, 0, :comments], %Comment{body: "ecneitaP"})
|> delete_at([:posts, 0, :comments, 1], mode: {:action, :delete})
|> insert_at([:posts, 1], %Post{title: "have"})
|> append_at([:posts, 2, :comments], %Comment{body: "my"})
|> update_at([:posts, 0, :comments, 0, :body], &String.reverse/1)
|> Ecto.Changeset.apply_changes()

%Category{
  posts: [
    %Post{
      comments: [
        %Comment{body: "Patience"},
        %Comment{body: "you", id: 2}
      ],
      id: 1,
      title: "must"
    },
    %Post{title: "have"},
    %Post{
      comments: [%Comment{body: "my"}],
      id: 2,
      title: "young"
    },
    %Post{title: "Padawan"}
  ]
}

Example application

There is an example Phoenix application with a dynamic nested LiveView form in the /example folder of the repository.

git clone https://github.com/woylie/ecto_nested_changeset.git
cd ecto_nested_changeset/example
mix setup
mix phx.server

Note that Postgres needs to be running to use the application.

You can access the application at http://localhost:4000.

Status

This library has a very narrow purpose, which means that even though it is young, it is unlikely that new functionality is going to be added or that the API is going to change. Should you miss something, though, don't hesitate to open an issue. Any issues and problems that may arise will be dealt with swiftly.

ecto_nested_changeset's People

Contributors

brianphilips avatar dependabot[bot] avatar renovate[bot] avatar woylie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ecto_nested_changeset's Issues

Removal not working after being persisted

Describe the bug
I've tried out the example and it seems that if you save either the "toy" or "pet", their removal no longer works.

To Reproduce
Steps to reproduce the behavior:

  1. Start the example
  2. Add an owner, two pets and two toys
  3. Save it
  4. Go back to edit, and try to delete either a toy or a pet
  5. See that clicking the "X" does

Expected behavior
Being able to delete either toy or pet once it is persisted.

Library and language versions:

  • main branch

Additional context
I've not been able to reproduce the issue on 5566acd.

My theory is that it relates to the new to_form in Phoenix 1.7

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update dependency postgrex to v0.19.1
  • Update dependency ecto to v3.12.1
  • Update dependency ecto_sql to v3.12.0

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • erlef/setup-beam v1
  • actions/cache v4
  • actions/checkout v4
  • erlef/setup-beam v1
  • actions/cache v4
  • actions/checkout v4
  • erlef/setup-beam v1
  • actions/cache v4
  • actions/cache v4
  • ubuntu 20.04
  • ubuntu 20.04
  • ubuntu 20.04
mix
example/mix.exs
  • ecto_sql ~> 3.6
  • esbuild ~> 0.5
  • floki >= 0.30.0
  • heroicons ~> 0.5
  • jason ~> 1.2
  • phoenix ~> 1.7.0
  • phoenix_ecto ~> 4.4
  • phoenix_html ~> 4.0
  • phoenix_live_reload ~> 1.2
  • phoenix_live_view ~> 0.20.0
  • plug_cowboy ~> 2.5
  • postgrex >= 0.0.0
  • tailwind ~> 0.2.0
mix.exs
  • castore ~> 1.0
  • credo ~> 1.7.0
  • dialyxir ~> 1.4.1
  • ecto ~> 3.7
  • ecto_sql ~> 3.7
  • ex_doc ~> 0.34
  • excoveralls ~> 0.18.0
  • stream_data ~> 1.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error near ",
],

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.