1

How to use Views to list all empty apartments, which do not have any tenant? So basically I have two content type: Apartment and Tenant as below.

Apartment content type:

  • Room
  • Tenant (entity reference to Tenant content type)

Tenant content type:

  • Name
  • Phone

Do you guys have any suggestion?

1
  • In the fields, i have content type: room, content type: referent to tenant, Views conditional if tenant is empty then output apartment and content: title. In filter criteria, I have content:type apartment checked. So they list all the empty room and also room has tenant. What i want is just empty room to be shown.
    – Tony
    Sep 7 '16 at 14:04
1

It's simple in Filter Criteria, click add and add your entity reference field.

enter image description here

When you are adding your field, for Operator, select Is Empty (Null)

Drupal 8 Example:

enter image description here

Drupal 7 Example:

enter image description here

12
  • Thank you. You are right, it is so simple. Why didn't I think about it? :D. Anyways, may I ask you another question? Is there anyway to use Views to keep a record of any change of tenant field in the Apartment content type? Because when tenant moves out and others move in a apartment, I want to keep a record of that. I have tried Track field changes, but it prints out only one change at a time.
    – Tony
    Sep 8 '16 at 6:09
  • You're welcome @Tony. If my answer solved your problem, which sounds like it, you can accept the answer by clicking on the check ✅, and a vote up, if you haven't already, would be appreciated.
    – No Sssweat
    Sep 8 '16 at 6:40
  • Thanks, I have already voted for it. If you have an answer or a suggestion for my question below, i appreciate it.
    – Tony
    Sep 8 '16 at 6:43
  • @Tony to answer your comment Question. If you're on Drupal 7, you can use the Rules module to store the value(s) of your tenant field in another field when your node is saved and if your value has changed. Else, if you're on Drupal 8, you will have to do this programmatically by creating a small custom module to do this for you.
    – No Sssweat
    Sep 8 '16 at 6:43
  • So your storage field is a field of unlimited values, and each time your entity reference field changes, you store the value that was there in here, then all you gotta do is add this field to views.
    – No Sssweat
    Sep 8 '16 at 6:48

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.