Add or Edit relation fields in Content Manager of Strapi - strapi

I am building a simple recipe website by Strapi. Now I want to make one Recipe has so many Ingredient. Therefore, there are two collections, They are in Many way relationship (Since I don't need to point back or link back to Recipe)
However, in Content Manager, I have to create some Ingredient items before creating one Recipe.
Is it possible to create or edit Ingredient while create Recipe in the same page?

Yes, this is possible using components in strapi. So basically, you'll need to create a Recipe collection and Ingredient component, and link to the component to Recipe collection as a repeatable component. So this way when you create a Recipe entry, you'll be able to add/edit the ingredients entries on the fly.
Have a look at this link to learn how to create a component.
Once you've created the component, follow the steps below to link it to the Recipe collection:
Edit the Recipe collection and add an existing component.
Set the component as a Repeating component.
Your model configuration should look similar to this.
Save the changes to the Recipe collection and then try creating an entry. You'll be presented with the following user interface that lets you edit/add ingredients on the fly.
Publish the entries and hit the find API will the populate key in URL like so:
http://localhost:1337/api/receipes?populate=ingredients

Related

How to add another table column in searchable array in nova?

i am getting data from different different tables and i displayed all those in one section that section contains search button also, i want to add another resource field as a searchable item in nova ,i am trying to add based on the relation of the particular table but it's throwing an error undefined column, How to add please help..
public static $searchable=['id','name','account.type'];
Basically, the search by relationship is not possible through Nova.
A package well made for your needs is this one: LaravelNovaSearch
This package includes both relationship search but also has other useful features making the search much more comprehensive.
Another package, which I have not personally tested, but which seems to be useful for your needs: NovaSearchRelations
My advice is to use LaravelNovaSearch, more maintained and more complete.

Filtering instances not related to the current contact

I have a custom entity Stuff and it contains a lookup to Contact. I created a 1:N relation with the latter as primary and the former as related entity.
On the Contact's form I added a subgrid and I only wish to list the instances of Stuff that have the lookup pointing to the currently viewed Contact. However, when I choose Only Related Records, the custom entity isn't in the list (despite it being related via the 1:N relation).
So, I'm using All Record Types, instead, but that shows all the instances of Stuff and not, as I wish, only those that are related to the currently viewed member.
So, what's the best course of action here? Should I do something with the relation? Or build a custom filter in JavaScript? How can I make the Stuff related to Contact if it's at all possible?
The image below shows the available conditions for the related entities. I notice that none of them relates to Contact, though. Do I need to activate it somehow or am I approaching it from a totally wrong angle?
So to give you more detail, you add the grid on the form:
(This is coming from the contact Form edit, after you press add subgrid)
you select there only related records, this are the stuff record i created:
As you can see only 3 of them has a lookup pointing to a valid contact, from there if you look at the grid, is showing only the related ones as you selected during the grid creation:
In any case i update the answer this is how the relationship is defined, and is a simple lookup created from the stuff entity:

How does Joomla create the Rules value in assets table?

I would like to know how does Joomla create the values in the Rule field in the #__assets table.
I believe that the files where they are created might be:
libraries\joomla\database\table\content.php
libraries\joomla\database\table.php
I have tried to find the code which does this but I either don't find it or what I do find just don't understand it. I need to know how Joomla creates these values in this field to be able to make my own process.
Every component controls its rules with an access.xml file. You will find these in the administrator/components/com_whatever folder.
Where specific rules are managed depends on the type of asset.
Component level rules are managed in com_config with the component mvc, meaning that when a user clicks the options button in the component they set the rules for the component.
Item level rules (such as for categories and articles) are managed in the form for those items via a field with type="rules."
Global rules are managed by com_config with the application mvc and the UI is in global configuration.
JTable manages storing this in the assets table.

Core data structure use multiple entities or not?

I have a Core Data model and I am trying to figure out how to structure it.
Lets say I have a Recipe. it has a name, title, image and 5 ingredients.
Would I make a recipe entity with recipeName, title. Then an Image entity with recipeName, imageURL.
Then an Ingredient entity with recipename, ingresient1, ingredient1measurwment, ingredient2, etc...
Or would I do it all under a recipe entity (but what happens if theoretically i create a recipe with 100 ingredients?
Also, I use recipeName because I think thats how you link them up?
Based on your question, I would create two different entities.
Recipe,Ingredient
where Recipe has a to-many relationship with Ingredient.
So, Recipe will have some attributes (the attributes you need) and a simple relationship called for example toIngredients. toIngredients is a to-many relationships. In other words, a recipe could have zero (or one if you want) ingredients.
In the same way, Ingredient has some attributes. In addition, it has a to one (inverse) relationship called toRecipe to its Recipe. Here you could decide also to have a to-many if your recipes could share ingredients but it strictly depends on what you want to model.
About rules for relationships, toIngredients has a cascade rule. When you delete a recipe, all its ingredients will deleted too. On the contrary, toRecipe will be of type nullify.
Here a simple schema of it.
where toIngredients is set as follows:
and toRecipe is:
Notice that optional flag for toRecipe is unchecked. This means an ingredient can exists only if a recipe exists. If you don't follow this rule, Core Data will complain about this.
About the image, it depends on how bigger are the images. Follow Marcus Zarra rules for deciding how to design your model Core Data - Storing Images (iPhone).

How can I add property to custom workflow activity that allows selection of another entity from workflow?

I'm working a custom workflow activity and would like to allow the user to select one of the entities available from within the workflow. This would be like selecting the entity in an update status activity. The list would include the primary entity, all of its associated parent entities, and any entities created within the workflow (e.g. if I created a task with the create activity, that task would be in the list).
Is there some way to do this?
Thanks!
Workflow has major shortcomings when it comes to things like this. You can add metadata to dependencies ( [CrmInput] and [CrmReferenceTarget("account")] ), but you'll need a property per entity you intend to support. I don't know if you could include multiple CrmReferenceTarget tags per property.
So even if you go through setting up a workflow activity with every lookup (which will require a code change for every new entity), you still have to take the care to set the right lookup in your code - and choose from ALL (not filtered based on your entity). Which is clearly not what you want.

Resources