尝试使用 FasterCSV 将 CSV 导入多个表

发布于 2024-08-23 15:20:29 字数 492 浏览 11 评论 0原文

我有一个 fastCSV rake 脚本,但它只导入到 1 个表。我正在导入产品,并且该产品在其他表上存储了几条信息。

当前脚本: http://gist.github.com/321889

我需要添加的是某种方式同时将产品信息导入到另一个表中。说出类别名称。

行,

  product.name = row[2]
  product.available_on = Time.now
  product.description = row[3]
  product.vendor_sku = row[12]
  product.price = row[13]#.to_d
  product.save(false)

在这种情况下:我需要像taxon.name = row[14] 这样的

这可能吗?

I have a fasterCSV rake script but it only imports to 1 table. I am importing products and the products have several pieces of info stored on other tables.

Current script: http://gist.github.com/321889

What I need to add is some way to import product info to another table at the same time. Say a category name.

In this case: the rows

  product.name = row[2]
  product.available_on = Time.now
  product.description = row[3]
  product.vendor_sku = row[12]
  product.price = row[13]#.to_d
  product.save(false)

I need an item like taxon.name = row[14]

is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏花。依旧 2024-08-30 15:20:29

尝试类似的方法:

associated_category = Category.find_by_name(row['Category'])
Produkt.create(
        :category_id => associated_category.id,
        :name => row[2]
        )

我这样做: http://gist.github.com/324613

危害

Try something like:

associated_category = Category.find_by_name(row['Category'])
Produkt.create(
        :category_id => associated_category.id,
        :name => row[2]
        )

I do it that way: http://gist.github.com/324613

Harm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文