ORM Cascading Proposal #41
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#41
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Proposal:
If the field type is struct or pointer to struct, it is has_one; If the field type is slice, map or pointer to slice or map, it is has _many. So I think the two tags could be merged to one tag.
there is still difference for has_one and belongs_to, check Active Record pattern http://guides.rubyonrails.org/association_basics.html#belongs-to-association-reference, as it's the basis for my suggestion
omitting 'has_many' seem a valid suggestion though
I'd like to see some support for many-to-many relationships too.
I want to use xorm cascade loading like below:
This sounds good.
type Device struct {
Id int64
User User
xorm:"index"
Name string
}
Wouldn't it make sense to reference back the User object instead of the UserId?
Of course, both yours and the below are ok.
cascade tag wording is like customer mapper for the FK field, but it's missing the owning issue, the meaning of "belongs_to" is the owning rights so it also meaning if owner got deleted the
meaning that a customer got deleted all its orders will be deleted too.
has_one is also required as there are situation where FK association is placed on the owner in most one-to-one situation
and still, delete face will also delete nose
has_one is very useful indeed.
Shouldn't we be able to specify if the CASCADE should delete? I'm coming from python to quite used to sqlalchemy and think they do it quite well. http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#cascades.
Realise you may not be heading the same way, but worth just checking.
@ahall I suppose Active Record by its infamous RoR framework is providing better example/pattern?
@ahall just read sqlalchemy the cascade served the save/update/delete behaviour, which is exactly the same usage from using grails, and grails is following active record pattern plus cascade mapping behaviour to override default behaviour, from my experience I've only find that "delete-orphan" mostly used.
Yep I'm only suggesting by default it wont cascade the deletes and you can use e.g. a cascade tag to specify if you want it to delete on cascade. sqlalchemy my default wont cascade the deletes unless you tell it to as you dont always want it to delete on cascade.
This would be extra nice to have. Has anyone started working on it?
I think currently no one is working on it. I think it should be discussed more.
Basic ORM preconditions:
One-to-One:
implementation notes:
One-to-Many:
Many-to-Many:
(yet supported)
Using has_many fetching strategy:
lazy:
eager_select:
eager_join:
Adding and Removing associations:
Only work on the inverse side of domain object for removing and adding associations:
Perfect work!!!
And some rules could be considered:
I've updated has_many clause usage above:
Which is a conflicted design to above comments.
extended to:
so you above example can be:
And with above design, it also means that for many-to-many declaration, that all 3 params are needed.
@lunny any thought on adding/removing many-to-many associations without adding new APIs?
For Many to Many, lazy load need a method to manually load the data, we have missed multiple has_many issue:
consider following a domain has multiple has_many:
Sounds good to me. Shame there is no way of auto lazyload due to language restrictions.
How to add or remove associations simply. It's currently diffculty.