0

Can anyone guide my to the best method or module to connect 2 fields together? I want to create a field called (Author) in a content type book, which will refer to a field called (name) in a content type author.

So a book author, will refer to field name of an actual existing author.

It's like creating a foreign key from the a book field to the author author field.

But the modules that I found (like node relation, relation and entity reference) only do a node reference, which is not what I want.

Not sure if I did use the modules correctly. But am I missing something here?

I am kind of new to Drupal as well as the web development era.

Any help?

1

Instead of using relationships use field collection module. In this module you may create a collection of fields that they all point to an entity.

As an example you can create author collection and in this collection insert first name field,last name field,gender field or any other information you need.

You can add this collection as a field to the book content type.

  • hmm, i am familiar with filed collection module, but this methodology will force the author to have a book 1st before adding a book!! because i already have "author content type, so i just wanted to refer his name to a book field. otherwise, it wont be to my convenience. – Abdulaziz Hamdan Jun 16 '15 at 8:15
  • In this way entity module will work, what is your problem with it? – M a m a D Jun 16 '15 at 13:16
1

Just wanted to say welcome to Drupal! :)

The Entity Reference module is what could help you. I think you're on the right track already.

The setup would be: Content type: Book - Author field (references the Author content type)

Since you're talking about foreign keys, the Entity Reference module does exactly that. In Drupal, it refers to the content using the foreign key(Node ID/Entity ID).

UPDATED

does entity ID mean the field reference in that node??

Yes, it does mean that.

For doing deeper on the field level problem. I haven't seen any module for that so far but my solution would be for somewhat for aesthetics only. Use the Book Author's name as the content type's title(You can change this label to like "Author Name"). So when you search authors in the entity reference field, you would be searching for the author's name.

Second option, if you don't want to use the title field of the Book Author content type but with this path I don't know what value you'll place there if you have a field called name would be to alter the autocomplete path of your Book content type's node reference field to use the field_name or any other deeper fields of the Book Author content type using form api's '#autocomplete_path'. So that when you search for an author, it won't match with the node title.

These solutions basically let's the user perceive that your doing a direct foreign key but it's, it still references the node id.

Hope I've helped with my explanation. :)

  • hmm, yes i know that entity referance can refer to the node ID, but i want to go deeper to the field itself!! does entity ID mean the field reference in that node?? – Abdulaziz Hamdan Jun 16 '15 at 11:38
  • I've edited my answer. Please check. :) – Leolando Tan Jun 17 '15 at 8:22
  • Thanks for your efforts to clarify, i leaned something from you, but its still not my case exactly.. because the content type author will have the title type of author!! but im actually having name field inside the same node which i want to refer to..i tried changing the note type ID as u suggested, but when i make a preview of what will show as buttons..its blank, even though that field which i want to refer to has data in it..same goes to when referring to other fields in that node, only title comes out to choose!! so im still not getting it, i appretiate your effot. :) – Abdulaziz Hamdan Jun 17 '15 at 13:35
  • Thank you! :) Sorry wasn't able to help but for "only title comes out to choose" that's what the second option was for. You would alter the autocomplete's output so that instead of the title, it would be the author's name or any other field you like. – Leolando Tan Jun 17 '15 at 13:58
  • tried the auto complete..but the same result. it tells me couldnt find entity, but when i write the titles' field it comes out straight. guess i'll have to find a way to code it and force it to refer to that entity (may have problem with db once modified)..or just leave it as standard text field. Thank you for your keen to help bro :) – Abdulaziz Hamdan Jun 18 '15 at 2:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.