Score:2

Connect field with Taxonomy Term

do flag

I have taxonomy Brand and different fields like RAM, Monitor, 'CPU' under content-type Hardware.

While adding a new Hardware how can I add RAM, CPU or other fields with Brands? e.g.

RAM = 16 GB, Brand = Corsair
Monitor = 24", Brand = Dell
...

I can allow Brand taxonomy to unlimited and can add multiple, but is that possible to connect with particular fields? Or is there any better approach?

Update:

Other solution I was thinking was to add multiple Brand fields like RAM Brand, Monitor Brand etc. Is this the only approach?

Score:1
cn flag

Let me make sure I understand what you are asking:

Brand is a taxonomy vocabulary.

Hardware is a node content type.

Hardware has fields:

  • RAM
  • CPU

Now, the question is, how do you specify different brands for RAM and CPU?

There are a couple ways to do this.

Create multiple Brand taxonomy term reference fields.

In this approach, you will add a taxonomy term reference field for each field on hardware that you want to set a brand for.

For example:

  • RAM
  • RAM brand (taxonomy term reference field)
  • CPU
  • CPU brand (taxonomy term reference field)

However, this is a bad approach if many pieces of hardware have RAM with the same capacity and brand (for example, you have 10 pieces of hardware with Corsair 32 GB).

The Drupal way: Create more content types

The most "Drupal" way to do this is to create content types for each "thing" you are trying to model and then combine them.

So, you would create:

  • RAM content type with fields capacity and brand ("brand" taxonomy term entity reference)
  • CPU content type with fields speed and brand ("brand" taxonomy term entity reference)
  • Hardware content type with fields RAM ("RAM" node entity reference) and CPU ("CPU" node entity reference)

This is the most flexible approach, although it takes a little more time to set up.

shyammakwana.me avatar
do flag
Thanks for the descriptive answer, I like both approach. For first example you said it's bad approach for many hardware, but I have other fields like serial number, manufacturer etc. So that should be fine right?
cn flag
@shyammakwana.me Yes, fields like serial number and hardware manufacturer are fine. The basic idea is that "each thing/object should have its own content type, and the fields for the properties of that thing/object should be on the relevant content type". So, it's fine to have a "HW serial number" on hardware, but you would generally not want "HW serial number" + "RAM serial number" on hardware ("RAM serial number" should be with RAM).
shyammakwana.me avatar
do flag
I see what you're saying. Segregating to the last thing/object is good approach. I thought to put RAM's serial number in "HW Serial Number" and RAM's brand in "RAM Brand" and likewise for Keyboard. But thanks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.