HABTM relationships in ExpressionEngine - expressionengine

Is ExpressionEngine capable of handling HABTM (has and belongs to many) relationships, even if it's with a plugin?
Basically, I have two channels: recipes and ingredients. A user needs to be able to create a recipe by assigning entries from my Ingredients channel, but when adding an ingredient they also need to specify additional data such as quantity. Is this possible?

Your answer lies in two indispensable EE add-ons by Pixel and Tonic: Playa and Matrix.
Playa is a many-to-many relationship fieldtype and module.
Matrix is a fieldtype which allows a single field to contain multiple rows of multiple predefined columns of data, each column of which can be a different fieldtype (including Playa).
So in your case, you'd have your standard Ingredients channel, then in your Recipes channel, you'd have an Ingredients field, which would be a Matrix fieldtype. In your Matrix field, you'd have one Playa column which displayed a dropdown of entries from your Ingredients channel, and another column that was a simple text input set to Integer for the quantity.

Related

how should create schemas for several mongoose models with different fields?

Suppose we want to build an e-commerce website that includes different products and for example these products are divided into four or five categories. Each category of products has its own fields and of course there are a series of common fields among them such as product name, price, description and ...
My question is, should we define four or five different schemas for each kind of product?
I do believe you should create one schema for each category of products, even though they may share some similar fields.
You can create one object for the similar fields and insert them into the Schema if it helps to not have to repeat yourself.
If one Schema have all the fields that all the products need, it would be too bloated. And it won't make sense to have different Models for each category too. When you query for a product, it will return many fields which do not relate to the product.

Filtering lotus-domino views that have multiple categories and multiple values

I am trying to design a view with multiple categories, and each document can belong to multiple categories at the same time.
For example, File A is in category:
1->a;
2
I can achieve this effect by specifying the columns as categories and access the document through various routes. However, I fail to specify which category the sub-categories belong to. This is what I am getting instead:
1->a;
2->a
The case doesn't seem too big of a difference but basically the view is returning every combination of the categories and the amount of entries can get very large.
I have tried to add the super category in front of the sub-category and try to filter out entries which the categories do not match the prefix of the sub-categories(e.g. 1,a), but I cannot find a way filter them out. Although the multiple values are shown in different entries, when I try to use the variable it extracts all the values.
Is there a way I can filter the entries based on that particular row instead of all the values? Or is there anyway I can achieve the effect through other methods? Thank you in advance.
You need to collapse Categories and subcategories into a single field. The Domino way to do this is to separate category and subcategory by backslash. So your category field would be something like:
"1\a":"2"
That ties the subcategory to the category. Or if you want to be able to find a document by subcategory only:
"1\a":"a":"2"
You then can use a little formula magic to get from the subcategory back to the main category (presuming the subcategories don't duplicate):
AllCategories := "1\a":"a":"2";
foundCategory := "a";
#Trim(#Replace(AllCategories;foundCategory:#Trim(#ReplaceSubstring(allCategories;foundCategory)));
This would return "1\a" (Note: the formula above is written is classic #Formula language, it is left as an exercise to the reader to translate that to the JavaScript formula equivalent)
Hope that helps

nopcommerce assign product on attribute combinations

I have a customer request that I would consider common for a cloth store, however not found a way to implemented it on NopCommerce.
The problem is that we stock t-shirts, jumpers etc in various colours and sizes, possibly separate the sex as well.
The actual products for sale are the primitive products with a particular design.
So Design 1, Design 2 ... Design N all use the same stock.
My idea was to be able to associate primitive products with a particular combination.
That is not possible on nopcommerce. I can only associate a product to a particular attribute value.
Any idea/solution?
You can use product attribute combinations in nopCommerce. Note: Attribute combinations are useful only when your Manage inventory method is set to Track inventory by product attributes
Follow the below steps.
Create a Product.
Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
add a condition on second attribute that if a value from first attribute is selected then only second product attribute should appear.
The first attribute selection will change the product image. The second won't.
Now if you remove the product image from first attribute, then second attribute selection will work.

How to Sort View control by Lookup column

I have two forms that are related and I would to combine them in a view control. Not that difficult. This is for a "1 to Many" type scenario.
Say I have a customer view with the columns customerID and Customer Name. Then I have a view showing the "many" documents that has the columns masterCustomerID, orderNumber, orderDate.
On the XPage I create a view control of the many documents and add the columns masterCustomerID, orderNumber, orderDate. Then I add a column in the front to do a DbLookup to pull in the actual name of the customer. Nothing too fancy really.
My question is, in this situation, where the lookup column is the FIRST column. What are the strategies to sort the view column by that column. By default it would sort by the Key Value in the order view which is likely different then the Name values.
I'm not averse to using repeat controls if that would be easier.
My first thought would be to employ TreeMaps somehow, but I don't know if that's practical in the event that there might be a LOT of documents. Maybe there's something I'm missing...
Any advice would be appreciated. Thanks
Use view with (Customer name, Customer ID) structure as main view. Then based on Customer ID populate other columns by lookup from view with structure (Customer ID, Order ID, Order date). Hence it is 1:N relationship, you can't use single view component, but two nested - repeat inside view column would do.
I hope you are aware of performance impact (orders looked up for every customer row), so don't try to show too many customers at once.

Sharepoint 2010 Exclusive columns?

Does anyone know a way to have two columns in a SP2010 list that are exclusive? I need to ensure that there is only a value for ONE column, not both.
Basically I need the following structure:
Category List ->
SubCategory List (with a lookup to Category) ->
Value (with a lookup to SubCategory).
But, if there is no SubCategory, use a lookup to Category. One or the other must be used, not both.
Using either a list Event Receiver (SPItemEventReceiver) or a Custom Workflow should be able to achieve these desired semantics.
I do not believe the model itself can represent such relationships. An alternative might be to have different content types, for which only one of the columns applies (to each).
Happy coding.

Resources