Hi there,
I wanted to open this issue purely for discussion purposes, but I think it's important. Inspired by the issue here #1238186: Can't build views relationship from a group entity to its base entity
I think that Relation should become part of Entity API. I see all major contributed modules (Profile2, Organic Groups) creating their own Relation code, which to me it doesn't make sense. A standardized approach would save a lot of headaches (imagine Views integration alone...).
OK, you may ask yourself, fine but why does Relation need to be merged with Entity API? Why don't modules simply implement this if they feel like it? Well that's because every Entity by definition is related to another piece of content. That's right, by definition. If the content were not related to something else, it would be a node. To repeat, an entity by definition has a relation.
True, I'm still fairly new to Drupal, and I don't want to come off as a n00b know-it-all, but sometimes it takes a fresh pair of eyes to see clearly.
Thanks
Comments
Comment #1
naught101 commentedHrm.. lots of entities have a number of basic relationships (eg. node-author, comment-node, etc), infact, I think all the core entities do (except possibly taxonomy vocab). But that's no proof that all entites are related to other entities by definition. There is no reason why some entity couldn't be defined that has no need for relation.
"If the content were not related to something else, it would be a node."
This makes no sense to me what so ever. You need to define your terms, as they aren't the standard drupal ones. Nearly all "content" in drupal is a node. Infact, that term is coming to replace the term "node" in the UI...
All that said, this is actually something that's been thought of (very vaguely!) for drupal 9+, ie. after relation settles down in d7, then is (hopefully, possibly) moved in to core in d8, then starts replacing some of those core relations that you mention. At the moment, I don't really know if there's anything that can be done with this, and to be honest, it might be better to start this discussion in the entity API issue queue...
Comment #2
nagiek commentedSure, let me elaborate. Let me know what you think.
Let's look at all Entities in Drupal. The most basic Entities are nodes and users. Entity API is used to build Entities that will all, somehow, relate to one of these basic entity classes. This is the point I'm trying to sell you on. I'm having a hard time doing it without just saying "name an entity that is not a node that is not related to another piece of content, and you won't be able to!". Still, that's my argument (very philosophical, isn't it). The definitions of node and user are broad enough to say that an entity must be an add-on description of either the subject (user) or the object (node).
Entity API is used to create these non-node non-user entities.
The reason I suggested the merge is for developers to have a standardized way to write these relationships, which they will all have to do. I agree that the timeline is far out, but I think it's the right direction to head in. Especially when more add on projects start to use Entity API (like Location or Signup) and they start to write their own Relation code.
Comment #3
naught101 commentedThat's in no way something you can assume. What about configuration-as-entities? That's something that's been discussed, and it's completely independent of nodes and users. There is no restriction on entities to have anything to do with nodes or users, or any other existing entity type, if it comes to that.
The last paragraph of my last comment still holds. I think the place to start this discussion is probably at Entity API.
Comment #4
nagiek commentedOK. It would still be nice to have default relationship code so developers didn't have to write their own.
Just curious to see what the Entity team thinks of this. Feel free to tell me I'm crazy.
Comment #5
bojanz commentedAs naught101 already told you, this is completely false. There's no actual reason to merge any code. You gain nothing.
Comment #6
nagiek commentedalright alright, I concede the point. There are unrelated entities.
I was just hoping to speed the adoption of standardized relationship code. The Organic Groups module currently has problems with the Views relationships from node to entity, which Relation solves. I figured would be a pretty common problem, hence the push.
Comment #7
fago>There is no restriction on entities to have anything to do with nodes or users, or any other existing entity type, if it comes to that.
Exactly.
>I was just hoping to speed the adoption of standardized relationship code. The Organic Groups module currently has problems with the Views relationships from node to entity, which Relation solves. I figured would be a pretty common problem, hence the push.
Entity API already cares about relations for you if you provide entity-property-info, i.e. if there is a schema field for it it generates views integration. This requires entity-type specific relations though, which should be the majority of all relations.