⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Relation 1-n without normal form



billy
  • profile picture
  • Member

Posted 19 October 2013 - 14:17 PM

Hello it's been a while since I started using Grocery Crud and I find it really very useful. 
I am struggling with this problem though: I have 2 tables with 1-n relation, which are not in normal form and they look like this:
 
Keywords 
   keyID (Primary Key)
   keyName 


Similarities
   similarityID (Primary Key)
   keyID  (Foreign Key)
   similarName
 
So as an example, the Keyword with keyName Objective-C would be related with the following Similarities records: 
           Keywords
       keyID    keyName 
         1     Objective-C


                      Similarities
      similarityID       keyID       similarName
            1              1          ObjectiveC
            2              1          Objective C
            3              1          Objective_C
 
I would like to be able to display in a single table view the current "Keywords" with their "Similarities". Something like this:
 
 keyName                                             similarName

Objective-C                         ObjectiveC, Objective C, Objective_C

 

Ideally I want to be able to add new Similarities through "Edit" menu, but if not possible it is less important since I could just do another view for just inserting new "Similarities"
 
I tried the code explained in the 1-n relation example but it does not work. It does not display any info from the "Similarities" table.

ceroberoz
  • profile picture
  • Member

Posted 21 October 2013 - 08:50 AM

just a suggestion, why don't you create another CI model, controller & view to display the single table and to be called later with "add_action" button?

or if you're using bootstrap, you can add the custom view in the modal of the current view.


billy
  • profile picture
  • Member

Posted 21 October 2013 - 17:00 PM

Thank you very much! I had not think of this solution.

I tried it and it's making things much more better. If I do not find any other way, I will keep it like this.

This is what i did in case anyone interested:

I added an extra button using the add_action  function and created another Controller that gets called when the button is clicked and retrieves only the requested rows with the specified "keyID" from Similarities table.

 

 

(Of course I am still searching for a way, if possible, to answer my original question.)


edramirez
  • profile picture
  • Member

Posted 11 November 2013 - 17:49 PM

I think you need to correct your table structure first and implement your design in a master-detail relationship. 

 

Regards,

 

Ed Ramirez