ruby on rails - how create object from query with includes -
Platforms and platforms are associated with the Caribbean as_to has_many
I have such a query for my DB
I want to use every ID of the platform associated with the p-variable and want to add it:
p = platform_category.where (Params [: platform_category_ids]). In the new object, like this: p.each {| Plat_cat | Campaign.create (..., some_id: plat_cat.platform.id)}
But PlatformCategory has many platforms and here I want to call everyone at block with plat.cat I do not think it's like Ruby.
UPD Everything is fine when I just array [1,2,3,4] like the array, but with the array in the parameter 'NoMethodError: The 'included' method for the array
Are you searching for this?
p = platform_category.where (id: [1,2,3,4]). () Join platforms Selection ('Platform.)
And then:
p.each {| Plat_cat | | Campaign.create (..., some_id: plat_cat.id)}
UPDATE : Since find
to contain
method because it returns an array after the query (if you pass an array as the argument) you can do this to avoid such a scenario:
P = PlatformCategory.joins (: platform). Selection ('platform.') Search ([1,2,3,4])
Comments
Post a Comment