Comments (3)
This is doable since the relation controls chain of persist commands, need to think about an API to avoid fetching... Let me think about it.
from orm.
@mrakolice technically it's possible when using Cycle, but are you sure it's a good idea to use Data mapper orm like this?
It will give too much control over persistence layer to you application layer if you modify database relations via ids
It's more usual to operate with relations as collection of objects (or inner object for HasOne case)
from orm.
$parent = [
'field1' => 'value'
'children' =>
[
['id' => 1],
['id' => 2],
['id' => 3],
]
];
All child entities exists in database, but child entity with id=3
not in this particular parent.
So, when I going to do smth like this:
$parent = $orm->getRepository(Parent::class)->load('children');
I can use only entities with [1,2]
id;
And this is what I can do with collection of objects:
$childIds = $parent->children->map(); // or load entities only with id via load method above
$entitiesToAdd = diff($ids, $childIds);
foreach ($orm->getRepository(Child::class)->where('id', 'in', $entitiesToAdd) as $child){
$parent->children->add($child);
}
$transaction->persist($parent);
$transaction->run();
This approach a bit sophisticated for me and I need to fetch entities to add from database, but this is just diff operation between two arrays, no matter - in php layer or sql layer.
If I do something like this:
$entities = $orm->getRepository(Child::class)->where('id', 'in', $entitiesToAdd);
$transaction = new Transaction();
foreach ($entities as $child){
$child->parent = $parent;
$transaction->persist($child);
}
$transaction->run();
This will be produce many update queries on sql layer.
I can use UpdateQueryBuilder (and I've solved this problem exactly via QueryBuilder), but I think, that this problem very viable for many developers, that using Cycle ORM or any another ORM. =)
from orm.
Related Issues (20)
- 💡 Elegant and efficient way to delete and update more entities at once HOT 3
- Update badges HOT 1
- 🐛 PHP 8.3
- CTE support for QueryBuilder HOT 1
- 🐛 fkAction/fkOnDelete has no effect for automatically created migrations HOT 1
- 💡 Add options set for auto-generated column values
- Cascade Persist Fails without cloning object in softDelete Method
- 💡 Cycle schema hydration is too slow
- 🐛 HasOne. select by relation property generates unnecessary INNER JOIN HOT 3
- Expected parameter of type 'Cycle\Annotated\Locator\EmbeddingLocatorInterface', 'Spiral\Tokenizer\ClassLocator' provided HOT 2
- Check useless `order by` on some ORM prefetches
- Index Names Not Applied to Database When Using Annotations HOT 1
- 💡 Embeddable Behaviors
- 💡 Allow setting enum cases as property defaults
- 🐛 In changelog version 2.8 is missed
- 💡 Ability to use `with` more than once with same relation. For several JOINs HOT 1
- 🐛 Issue with Enum Field Difference Detected During Database Migration Synchronization
- 💡 Efficient bulk-loading of morph relations
- 🐛 Self transation cannot be resolved. HOT 4
- Duplicate entry for primary key 🐛 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orm.