How to save object in cfwheels and save data to an associated table with comma separated values out of an input field?

117 Views Asked by At

How do I save my object in cfwheels and add data out of a form input field in the form of a comma separated list and save this data in a related table?

My form passes the data to the controler in the params struct. There is the field "tags" wich holds the values like "Apple,Pear,Banana".

How can I save this data to a second related table? Is it possible without a second query and without a transaction?

This is the simplified controller:

public void function create() {
news = model("News").new(params.news);
news.save()
}

The normal object data should go to the table news The related data to tags

I created the associations in both models.

1

There are 1 best solutions below

0
Daniel On

based on the info you have provided it's hard to give more feedback than this:

public void function create() {
  news = model("News").new(params.news); //<- this is enough
  // news.save() //<- not needed
}

You may need to include the post/get data, the models, as well as a description on what is the result and what is the expected result.