I'm using a join table and would like to know a better way to loop
through my ids
and insert into the join table in the model instead of the controller.
This is what I use in the controller and it works fine, but when I do
a beforeCreate() in the model that calls my
insert function it's not getting my 2 variable sent to that function.
So my questions:
How to pass my 2 variables from the controller to the model.
How to loop through the saves in the model.
Is there anything wrong with the way I have it working from the
controller now?
Thanks
<!--- create function in my controller --->
<cffunction name="create">
<!--- multiple select city ids from form --->
<cfset var mynewid = restaurant.id>
<!--- multiple select city ids from form --->
<cfset var idlist = params.cityid>
<!--- Loop through ids, insert into db --->
<cfloop index="i" list="#idlist#" delimiters=",">
<cfset restaurantCityBridge = model(" restaurantcitybridge").new()>
<cfset restaurantCityBridge.cityid = i>
<cfset restaurantCityBridge.restaurantid = mynewid>
<cfset restaurantCityBridget.save()>
</cfloop>
</cffunction>
--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.
Yes, and the restaurant.id is the newly inserted id of the restaurant.
Thanks
On Mar 24, 5:57 pm, Chris Peters <ch...@clearcrystalmedia.com> wrote:
> Are you creating a new restaurant just before adding the
> restaurantCityBridge data?
>
> > cfwheels+u...@googlegroups.com<cfwheels%2Bunsu...@googlegroups.com>
> To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
On Mar 25, 3:19 pm, Per Djurner <per.djur...@gmail.com> wrote:
> I would create a new function in your model CFC file and just pass
> everything into it.
> That would keep your controller cleaner and you can call it from other
> places of your code in the future without duplicating too much code.
> Also think about whether you need to wrap your code in cftransaction
> tags (since you are causing multiple database calls behind the scenes
> it's a good idea to use transactions so that either all of them gets
> executed or none).
>