Providing CNR-like capabilities http://drupal.org/project/cnr for this module would be ideal

"It syncs the entity reference fields between two entity types which have a entity reference fields to each other, so double editing entities is no more needed. If one entity has a reference the other entity receives also a reference to the saved entity if it is referenced in that entity."

Comments

jm.federico’s picture

Status: Active » Postponed

It certainly is a useful functionality, and I might end up developing it.

I'm still trying to figure out if what that tries to do is creating a relationship, which could potentially be accomplished with http://drupal.org/project/relation

If you can provide a patch, I will really appreciate it, if not (and nobody else does), chances are, if I see enough interest, I'll develop it.

WIll mark as postponed until I have the time or need for it.

TimelessDomain’s picture

Just throwing this out there for future development eyeballs...
Extending this with field mapping/ sharing in between corresponding entity references would be amazing.
NAT http://drupal.org/project/nat for D7 allows you to do this between b/w corresponding Vocabularies & Content Types, but this should be extended to all types of entities.

Relations is nice, but Corresponding Entity Reference Fields may be able to provide more capabilities long-term. For ex. with the Field Sharing in between Corresponding Entities, you could have multiple entities composing other entities. Then whenever one of the multiple entities is updated, it would auto-update the mapped to entity. If the mapped to entity is updated, it could update multiple other related entities automatically..

UI: Upon selecting corresponding entity references, you are given a list of fields to map between entities.

Extend by
- selecting 1-way or 2-way field mapping between corresponding entity references

if this is too advanced for this module, I will post over on the Relations issue queue. Though, these features will eventually logically be needed to be developed. I like the idea of just having the "Entity Reference Field" & "Corresponding Entity References" modules since it would seem to be simpler than determining relationship types as the relations module seeks to make you do.
Thanks

TimelessDomain’s picture

This module should be developed regardless of "Relation" module.

The relation module requires that you choose relationships via a "relation_dropzone block."

According to http://drupal.org/node/988970#comment-4340216 "Fields are no longer part of the core (Relation) module"

Controlling relationships via fields is more ideal. Pulling relationships out of fields seems to be a step backwards.

jm.federico’s picture

You're right, I remember having issues with the fact that the relation was not a field but an entity, which seemed to complicated for my taste.

Right, so I've made a decision, this will be part of the module. Can't give a schedule, but will be here, and if someone is willing to start, please do, I'll accept the help and will give credit where credit is due.

Best to all!

jm.federico’s picture

Status: Postponed » Active

So! Problem!

Here is how I imagine things should happen:

I create two fields, on two different entities. I then create a mutual reference for the fields, so that they get updated when a reference is created/updated/deleted.

To update the referenced entity we would need to know what the function to save such entity is. And right now it is not possible. This leaves us on a bad position.

I found this function field_attach_update() (http://api.drupal.org/api/drupal/modules--field--field.attach.inc/functi...) which is used to save an entity field values, and I think it might be done by doing an entity_load() and then invoking field_attach_update() but that might be assuming a lot. For instance we are taking revisions out of the equation right away. Plus there would be no hooks called around the update of the entity, bad bad bad.

So, what I'm thinking is, until there is a way of invoking entity_save on every entity, this functionality should reside on a separate module, which can have a dependency on the entity API module, which provides such function (entity_save) and can create special cases for known entities that do not use the entity API. But I don't think it is a good idea to create such dependency for this module, and I want this module to be as generic as possible.

I'm leaving this issue open to hear opinions.

jm.federico’s picture

I'm happy to announce that the first commit towards this has been made

Latest DEV includes a submodule that syncs fields across entities:

Some notes:

  • Entity APi modules is required
  • Entities must be compatible with entity_save()
  • Works better with unlimited value fields
  • Can create duplicate references
  • Both fields must be setup independently, if they are not pointing to synch both ways things might go wrong.
  • To have fields listed as available for sync, 2 fields must exist and must be present in all of the bundles that they can reference (see note below).

How to set it up.

If you have Entity A and Entity B, and want to reference them, create a field ref_b and put it in every bundle from Entity A that ref_a can reference, and a field ref_a and put it in every bundle of Entity B that ref_b can reference.
Once that is done, go back to the field edit page and you should see them listed in the sync option.

Please test and let me know what you think.

CHEERS

domidc’s picture

@jm.federico I m one of the corresponding node reference maintainers and a lot of problems you list we already solved. I think you can reuse a lot the logic in cnr and apply it to entities.

jm.federico’s picture

Thanks for the heads up

I downloaded your module a few days ago and I'm basing my logic in yours. Very nice module indeed.
Problems are more because of time than because of solutions in this case. Your module has given me plenty of good ideas.

If you are interested in helping out here I would be more than happy to give you co-maintainer access to this module too.

Cheers

domidc’s picture

Yes go ahead make me comaintainer. I ll see what I can do. The company that is currently hiring me is interested in contributing to drupal so entity references might receive some dedicated time.

TimelessDomain’s picture

This is great! looking forward to seeing what we can brew up!

jm.federico’s picture

@domidc

You are now co-maintainer of the module. Happy coding!

jm.federico’s picture

Status: Active » Fixed

Hello!

Beta 1 ships with a backreferencing module. Two fields can now be kept in sync.

Will mark this as fixed. If there are any problems, please open a new issue with a bug request.

Cheers

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.