数据库 请教一个问题关于数据库表的问题

Unknow user · December 03, 2011 · Last by ywencn replied at February 04, 2012 · 2060 hits

我现在有两个表。分别是 catalog 和 artcle。 我知道怎么从 catalog 里把 artcle 的内容调出来。

c = Catalog.find(id=1)
c.artcles.all

问题是我不知道怎么从 artcle 去调用 catalog 里的数据。表关联已设置好了。

c = Catalog.find(id=1) @article = c.artcles.first @article.catalog 一对多的化

你思路不对,不应该想到两个表怎么调,应该是两个模型之间怎么调。 你的问题在这里都说得比较清楚了 http://guides.rubyonrails.org/association_basics.html

You need to Sign in before reply, if you don't have an account, please Sign up first.