OpenFarm icon indicating copy to clipboard operation
OpenFarm copied to clipboard

Add companions and linked crops to a crop.

Open simonv3 opened this issue 8 years ago • 18 comments

We currently have a parent and a taxon for each crop. It would be great to also have a

has_many: companions, class_name: 'Crop'
has_many: linked, class_name: 'Crop'

for each crop. Linked crops are just associated with a crop.

I would do this by adding the required field and the inverse of that field to each crop.

Then for the edit page you would add a search modal for crops.


Old ticket:

Let's make our tree of life a better tree

Better taxonomy!

We currently have a "parent" crop, but it might also be interesting to have a couple of other fields - for example "linked" which would link a "plum tree" to a "fruit tree". If that were the case, I would make also add an "abstract" field - for example, a fruit tree is valid crop to create a guide for, but it shouldn't show up in our list of "crops".

So the current crop model already has a reference to parent crops, but we should be let users be able to add parents. Ditto for varieties.

I would also suggest adding:

has_many: companions, class_name: 'Crop'
has_many: linked, class_name: 'Crop'

Related to #641 and #715.

simonv3 avatar Aug 30 '15 16:08 simonv3

I think this all sounds good but I need some clarification.

a fruit tree is valid crop to create a guide for, but it shouldn't show up in our list of "crops".

Are you suggesting that we have crops and abstracts? How would one find the Guide that is written about a fruit tree if fruit tree wasn't a crop?

The most simple way I see the fruit tree case being handled is just let it be a crop. Even if that isn't technically accurate. That way people can write guides about it, add it to their gardens if they wish, find it in search and via the API in a simple way. Then more specific crops or varieties can list that other crop as a parent.

roryaronson avatar Jun 17 '16 01:06 roryaronson

Yeah, you're right - I think I just want to separate it somehow from real "crops" but what does that even mean?

simonv3 avatar Jun 17 '16 01:06 simonv3

That's kind of what I'm thinking. As soon as we start "forcing" certain definitions then all the edge cases come out. I think letting the community figure out what they want to write guides for and just having one thing to write them about (crops) will be easiest. Then we can support organization with meaningful linking such as companion, parent, and child as well as tagging such as category, genus, family, variety, etc

roryaronson avatar Jun 17 '16 01:06 roryaronson

So in the plum & fruit tree example, how would you lay that out?

simonv3 avatar Jun 17 '16 01:06 simonv3

  • Fruit Trees would be tagged with category and link to Prunus as a child
  • Prunus would be tagged with genus and link to Fruit Trees as a parent and Apricot as a child
  • Apricot would be tagged with variety and link to Prunus as a parent
  • Companion Plant to Apricot would link to Apricot as a companion

roryaronson avatar Jun 17 '16 01:06 roryaronson

Okay, that makes sense to me. So in the crop creation field we'd probably need a dropdown saying "is this a ____ (category, genus, species)".

simonv3 avatar Jun 17 '16 01:06 simonv3

Sure. Why don't we just call that the taxon then? I mean, that's what we're describing. Each Crop in the db is either a variety, species (the default), genus, family, or something even higher. And then let's include a catch-all other option and see what people do with it. 2000px-biological_classification_l_pengo_vflip svg

roryaronson avatar Jun 17 '16 01:06 roryaronson

the tree of life is a trippy mushroom.

simonv3 avatar Jun 17 '16 02:06 simonv3

So you're thinking of making "category" other?

simonv3 avatar Jun 17 '16 02:06 simonv3

I'm thinking each crop should have a taxon. The possible options for the taxon field are all the things in the trippy mushroom plus "variety", "cultivar" and "other".

roryaronson avatar Jun 17 '16 02:06 roryaronson

Okay, but I just want to make sure - would there still be a "category" link in that case, or would that just fit underneath "other"?

simonv3 avatar Jun 17 '16 02:06 simonv3

No category link. Just other.

roryaronson avatar Jun 17 '16 02:06 roryaronson

great, I think I'm on the same page as you!

simonv3 avatar Jun 17 '16 13:06 simonv3

Hi, This is my first ever attempt at this scary OS thing. After reading the comments above a million times, this is my understanding of the steps to be done (I might be totally off). In models/crop.rb add has_many: companions, class_name: 'Crop', inverse_of: :linked has_many: linked, class_name: 'Crop', inverse_of: :companions

and in show page maybe between line 51 and 52 <td><%= I18n.t('crops.companions') %></td> <td><%= @crop.companions_array.join(', ')%></td>

and for the edit page, a text area like that of 'Common names' be created for 'companion crops' and 'linked crops'?

Please let me know if i have got that correct or maybe just a little correct?

jiimms avatar Feb 08 '17 19:02 jiimms

Hey @jiimms that's super exciting that you picked OpenFarm to be your first OS project! Welcome, and we're really glad to have you :)

Looks like you're definitely on the right track!

There's a difference between companions and linked, which might be confusing. Companion plants are plants that grow well together, while linked plants are plants that just have a link (eg. Plum trees are linked to fruit trees). In our architecture I think we're ignoring linked for now (it's kind of already implemented in crop.rb as a parent -> varieties link), so I think the model in crop.rb would just look like:

has_many: companions, class_name: 'Crop'

And it would be the inverse of itself. Though I'm a bit rusty on my RoR, so I might be missing something. But essentially companions ≠ inverse of links.

Then in the "edit" step I think it's potentially a bit more complex. I think we'll have to suggest crops to a person as they're typing them. We could do it by slug or id for now, but that doesn't seem like the most user friendly or fail-safe approach. So an input field like the search form that on select adds the crops to a list?

Then you'll also need to make sure that companions are added to the crop serializer for the API to put it out and accept it and the mutations will also need to take them into consideration for creating and updating - maybe in the crops_concern file?

Let me know if you have any questions about this, and definitely feel free to ping me on Slack directly if you want to.

simonv3 avatar Feb 08 '17 21:02 simonv3

Thank you @simonv3 for the welcome, kind words and also for explaining the task some more but I think I will definitely be back with a few more questions on slack.

jiimms avatar Feb 09 '17 18:02 jiimms

I think I am more of a beginner than I imagined myself to be :-) Still trying to find my way around the edit task. Just giving an update that i haven't abandoned it but its taking some time.

jiimms avatar Feb 16 '17 17:02 jiimms

That's great, thanks for the update @jiimms. Keep us posted on how it's going. Take your time, and ping us if you have any questions :)

simonv3 avatar Feb 16 '17 17:02 simonv3