2

For my property management admin application I want to assign charges of different types to the properties being managed (e.g. service charge, utilities bill, maintenance costs etc.). So each property on an estate will have many charges associated with it.

In my original spec I have a table for properties/flats and an table for charges that records a foreign key from the property table in order to associate a charge with a property.

New to drupal I implemented this by creating a content type for properties and a content type for charges with a entity reference field to record which property node is related to which charge node. Next I will look into building a form that allows me to fill fields from more than one node at a time and some code to grab the correct property and autofill the entity reference field when adding a new charge by selecting say. 'add charge' from a page that lists properties.

Now I have doubts. I could also create a field collection with all the fields required for a charge (type, amount, date, comment) and allow unlimited values for this field collection. As this field collection is stored as an entity, doesn't this do the same thing as above without having to use the entity reference field and so avoiding some of the coding? Also, if I wanted to add a charge to many apartments at the same time, wouldn't it be simpler using a field collection?

I am too new to drupal to understand the difference. I now it is related to what I want to do with the data after it is stored (it should be available for use in calculated fields, to be listed with data from other nodes, searched for by charge type, for instance) but I don't know how to know which is better without building it twice!

1 Answer 1

1

Good question, but hard to answer. I can't tell you what to choose but I hope my thoughts will help.

If I understand your needs correctly, Field Collection definitely has some advantages. Firstly, field collections are purpose built to be related to other entities. Each field collection entity is always related to one (and only one) node. That seems so match your use case, although I wouldn't know how if it's easy to add multiple field collections to multiple nodes at once. In my experience, field collection provides a pretty smooth way for site maintainers to add new data, so that's good.

The downside of field collections is that many contrib modules are still node-centered. For every site you build, it's hard to predict which problems you will be solving or which features you will be adding 6 months after the launch. If you decide to use field collections, you may find yourself in a situation where you want to add something that would have been really easy with nodes.

Since you're exploring different solutions, maybe you should also look at Drupal Commerce, if only for inspiration. It's a really flexible system which adds line item entities to orders more or less like you want to add charges to properties.

2
  • 1
    Thanks, yes that helps. I hadn't thought about the fact that contributed modules might be aimed at nodes specifically. That is the kind of consideration I want to take into account, so thank you. I will read up on how to install a drupal distribution alongside my current site and I will give Drupal Commerce a go. Merry Christmas. Dec 24, 2013 at 18:48
  • 1
    You're welcome, and thanks for the feedback. For development and for trying out stuff without breaking your 'real' site, I highly recommend setting up a development environment. Even faster, but limited to max. 30 minutes, is simplytest.me, where you can spin up a test site with one or modules with the click of a button. Dec 24, 2013 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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