Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 Elegant and efficient way to delete and update more entities at once #443

Open
tenmajkl opened this issue Nov 8, 2023 · 3 comments

Comments

@tenmajkl
Copy link

tenmajkl commented Nov 8, 2023

I have an idea!

Currently, when you want to delete or update multiple items, you have to either iterate through them or work with query builder. The query builder solution works, but it doesn't have relations by default and you need to specify table name, so I think that it would be great to have something like Repository::update. The only problem that the default repository is made for Select statements so I'm not sure if that would be possible. I can add it, but I don't know the cycle codebase well at the moment.

@roxblnfk
Copy link
Member

roxblnfk commented Nov 9, 2023

Hello. Please share how you imagine the API. What would the end user code look like?


Btw, you might be interested in looking at a small example of how it's possible to implement ActiveRecord based on the Cycle
https://github.com/roxblnfk/cycle-active-record

@tenmajkl
Copy link
Author

tenmajkl commented Nov 11, 2023

Something like

$orm->getRepository(User::class)->update([
    'name' => 'foo'
])->where('name', '!=', 'bar')->run();

or since repositories are read only:

$manager = new \Cycle\ORM\EntityManager($orm);
$manager->update(User::class)
        ->set([
            'name' => 'foo'
        ])
        ->where('name', '!=', 'bar')
        ->run()
;

But I'm not sure if this would be possible

@roxblnfk
Copy link
Member

It looks like a request for a new interface Cycle\ORM\QueryBuilderInterface with methods select($role): Select, update(...) and delete(...)

The select() method just returns the Cycle\ORM\Select class.
update() and delete() methods must provide fields mappings and relation joins like in the Select class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants