openfarmcc / OpenFarm

A free and open database for farming and gardening knowledge. You can grow anything!
https://OpenFarm.cc
MIT License
1.57k stars 242 forks source link

Add companions and linked crops to a crop. #683

Open simonv3 opened 9 years ago

simonv3 commented 9 years ago

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.

roryaronson commented 8 years ago

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.

simonv3 commented 8 years ago

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

roryaronson commented 8 years ago

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

simonv3 commented 8 years ago

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

roryaronson commented 8 years ago
simonv3 commented 8 years ago

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)".

roryaronson commented 8 years ago

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

simonv3 commented 8 years ago

the tree of life is a trippy mushroom.

simonv3 commented 8 years ago

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

roryaronson commented 8 years ago

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".

simonv3 commented 8 years ago

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"?

roryaronson commented 8 years ago

No category link. Just other.

simonv3 commented 8 years ago

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

jiimms commented 7 years ago

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?

simonv3 commented 7 years ago

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.

jiimms commented 7 years ago

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 commented 7 years ago

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.

simonv3 commented 7 years ago

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 :)