MANY_MANY and Form

Hi all,

I have 3 tables. table1 which has a MANY_MANY relation ship with table3 and table3 has a MANY_MANY relationship with table1

I create so a table2 which "implements" the relationship between table1 and table3

Problem is when I want to populate the database with Admin Create.

I did a _form for table1 on which I enter every infos =>works fine.

I did a _form for table3 on which I enter every infos => works fine

But as a noob, I wonder where I can populate the table2 :lol:

(In table1 model and table3 model I indicate the type of relationship)

Does a way exists to populate table2 inside the _form view of table 1

What is the way to do this, up to you ?

Thanks for your precious help

You can collect tabular input.

You can create a checkbox in the form of table1 with elements of table3 as id.

In the controller you parse the array of values and save the model of table2.


isn’t there another code example than the one provided in the tutorial ?

I must admit that it is a little bit obscur for me.

I also find it not easy to understand for a beginner…

Let’s pretend that table1 is a BlogPosting, table3 is a Category, and table2 is a BlogPosting_Category (aka an association table between the two former)

I would recommend doing it "one item at a time", instead of bulk, as this is probably what your users will do anyways.

  • Have a list of associated categories on the BlogPosting form page, with a delete button for each category

  • Have a form field on the BlogPosting form page where you can add an associated category

Then you can add or delete an association one at a time. These should point to methods on the BlogPosting controller, such as AddCategory or DeleteCategory. You’ll have to pass the BlogPosting ID and the Category ID to the controllers.

You can’t generate CRUD operations for BlogPosting_Category, but you don’t really want to. All you need is the model for adding and deleting them ActiveRecord way.

Some more info here:

There is this extension for tabular input.

As you are doing something of more and more simple, I advice you just to read the code and the sample and to copy only the needed parts.

Try at least to start something on your own, if you will need further support I will be glad to help you, but as you are at the "green field" status is a bit difficoult to give you an actual help.

спасибо zaccaria

не за что, Аяксиян!

(for not-russian speaker, is just thank-you your-are-welcome, noting of interesting)