What you have is a many to many relationship. Any given record in Model can link to any number of records in icons. (Your mouse needs blue tooth and USB.) But any given icon can be linked to many different models as well. (You have 2 Mice and 4 external drives that need the USB icon...)
Start with these relationships:
Model::pkModelID = Model_Icon::fkModelID
Icons::pkIconID = Model_Icon::fkIconID
For an explanation of the notation that I am using, see the first post of: Common Forum Relationship and Field Notations Explained
You can place a portal to Model_Icon on the Model layout to list and select a Icons record for each given Model record. Fields from Icons (such as the container field) can be included in the Portal to show additional info about each selected Icons record and the fkIconID field can be set up with a value list for selecting Icons records by their ID field.
And you won't need any check box field as it has been replaced by records in the Model_Icon table. But you can produce what looks and acts like a check box format if you want with scripting and conditional formatting.
The following many to many demo file includes an example of such a layout design: https://www.dropbox.com/s/oyir7cs0yxmbn6i/ManyToManywDemoWExtras.fp7
Users with FileMaker 12 or later can open this file from the File menu to get a copy converted to the newer .fmp12 file format.
Your demo file is very helpful and the checkboxes layout seems to be exactly what I was looking for! How did you make the checkboxes though? I tried to make them the same way you did, but it can't be toggled. I think the only thing I did differently was that because I did not have a diminishing value list layout, I just made it go to the join layout and made the fields in set field from join too. Is that why it does not work like yours, or is it something else that I have missed? Is there a way to get it to work without the diminishing value list layout?
The script looks correctly written. IF there's an error in it, I'm not spotting it.
Did you set up the Rectangle object and layout text as a button so that clicking it performs the script?
Did you add a conditional format expression to selectively hide/show the "x" character in each row of the portal?
Do you have FileMaker Advanced? If so, you should enable the script debugger and data viewer, then try clicking to perform this script so that you can step through the script and watch the values in the fields and variables change with each step to see if you can sport where this is going wrong.
I did forget to make it a button and use conditional formatting. I managed to make it a button, but the conditional formatting part for the x is still confusing me. I got it so that it can change colors. How do you set it up so that the x disappears/ reappears when clicked?
In the conditional formatting dialog, click the "more formatting..." button and specify that the font size change to a very large size. When text is a single row in the 10-12 point font size, changing it to 120+ points is enough to make the text disappear from the text object.
Thank you! It works now :)
I tried to remake the scripts and layout in my main file because eventually I would like to work in a popover box, however I have come across a weird problem. The field names, tables, relationships, scripts, conditional formatting, layouts are all the same, but when I click on the button the x does not reappear and the script does not delete, it only creates new records.
I tried to figure out what the problem was but I'm really stumped. Is it the conditional formatting?
With FileMaker 13, we can now use the "Hide When" setting in the inspector to make items appear and disappear on our layouts.
Where does the pop over come in for what you are setting up? WHere are you placing that button and what are you putting in the popover frame?
The pop over is going to be on the model layout with the Icons and IconsAll portals and a button to print icons. If people click on the icons button to open the pop over, they will be able to see which model has bluetooth, usb, etc, and can change it by clicking the x if they want.
I noticed that it wasn't working in the pop over so I decided to try it out in a new layout in the actual file people were going to use. The scripts and conditional formatting that were working in a sample filemaker file was not working in the layout. The only difference between the sample file and the actual file was that the sample file only had the five table occurrences that you see in the relational graph.
Actually I should say it works but it does not delete, the script just continues to add records in the join table. I still haven't figured out how to get the delete part to work.
The Popover should work, but if you place a popover button inside the portal and use it to try and show a portal, it won't work as this appears to violate the "can't have a portal inside a portal" rule.
If you have FileMaker Advanced, you could enable the script debugger and then test this script's ability to add/delete records to see where this goes wrong.
Best guess at this point is that your script is losing the portal row focus before capturing the needed values from the clicked portal row.
Oh, I am putting the portals inside the popover not the other way around. It doesn't work if I do that? I don't mind just making a button to go to another layout if it doesn't work. Right now I am testing it out in another layout without the popover but the conditional formatting and the delete part of the script is not working as it should.
I found a filemaker 12 advance on my work computer and tried the script debugger.
You can't put a portal into a popover frame if the popover button is also in a portal row. When you try to do that, the portal object "falls through" the frame to end up on the layout behind the frame.
An unamed button is any button that has not been given an object name. Most buttons are not named.
If you click the second button from the left, you can execute the script one step at a time while watching the results produced by each step. If you click the x= button, you'll open a data viewer where you can watch the values of fields and variables change while you step through the script.
Thank you Phil for explaining how to use the script debugger. The x= button was very useful! I tried running the add/delete selected icon script and the set variables work. Right after the If statement, it skips all the steps from go to layout until the else.
Which would indicate that the If step is not evaluating to False when you expect it to. That's typical of either a loss of portal row focus or a relationship that isn't working as expected.
You can use the plus sign on the Watch tab and copy and paste the full expression into a "watch" expression. Once you have advanced the script in the debugger to that point, you can use that expression to see how it is evaluating. You can also isolate parts of the expression such as the list function or the filtervalues function to see how they are evaluating to see if that helps you zero in on what is keeping this from working.