我的公司有一个老网站,这个网站是多年前在PHP建造的。 我认为,数据库图示是从战略角度考虑的要求的缓慢积累。 现在,我们正在推出PHP代码,并利用铁路建造该地。 数据库图形仍保持不变。
我只是把我的头 head放在铁路上,因此这或许是一个简单的问题。
我有一份数据看似如此的文章:
id: 1102129
article_type_id: 5
old_article_id: 0
title: Zombie Film Locations
subtitle: Hollywood-inspired survival tips for destinations teeming with the undead
display_date: 0000-00-00
author_id: 29
thumbnail_image_id: 12033473
index_image_id: 12033473
article_image_id: 12033473
is_archived: 0
is_featured: 1
is_published: 1
date_to_show: 2011-10-04 00:00:00
off_the_path: 0
created: 2011-10-04 12:45:07
modified: 2011-10-11 15:33:59
fact_check_date: 0000-00-00 00:00:00
unpublish_date: 0000-00-00
is_qsfeatured: 1
featured_order: 0
第二行:
id: 1102128
article_type_id: 14
old_article_id: 0
title: Hotel Adagio [id]35677
subtitle: Hotel Adagio
display_date: 2011-09-29
author_id: 0
thumbnail_image_id: NULL
index_image_id: NULL
article_image_id: NULL
is_archived: 0
is_featured: 0
is_published: 1
date_to_show: 2011-09-29 12:50:38
off_the_path: 0
created: 2011-09-29 12:50:38
modified: 2011-09-29 12:50:38
fact_check_date: NULL
unpublish_date: NULL
is_qsfeatured: 0
featured_order: NULL
图像数据如下:
id: 6722
old_id: 0
type: Index
association_type: TopTen
association_id: 1102129
position: 0
copyright: AMC
caption: The Walking Dead portrays an abandoned, corpse-ridden downtown Atlanta, one of 10 zombie film locations we ve scouted out to help you survive (and hide) should the dead rise.
alt_text: Zombie film locations
url: photos/index-TopTens/walkingdeadindex.jpg
_url:
name: index
published: 0
description:
第二行:
id: 6723
old_id: 0
type: Thumbnail
association_type: TopTen
association_id: 1102129
position: 0
copyright: AMC
caption: The Walking Dead portrays an abandoned, corpse-ridden downtown Atlanta, one of 10 zombie film locations we ve scouted out to help you survive (and hide) should the dead rise.
alt_text: Zombie film locations
url: photos/thumb-TopTens/walkingdeadthumb.jpg
_url:
name: thumbnail
published: 0
description:
图像表中的协会是该文章的背书,尽管数据库中没有外国钥匙。
在我获得这篇文章时,我如何掌握所有图像?
我现在担任控制者:
@articles = Article.where(:article_type_id => 5).order("id DESC").limit(5)
在我看来,我确实像:
<%= article.title %>
But how can I reference the images, from the article model?
To make this more complicated, the images are polymorphic, so I can not simply create a foreign key from images to articles. Images also sometimes get mapped to "travel_guides" and "slideshows", which are 2 other tables we have.
最新资料:
改变 该条现在规定:
has_many :images, :foreign_key => association_id
修改我的控制器法,以便:
@articles = Article.where(:article_type_id => 5).order("id DESC").limit(5).joins(:images)
但我认为我确实:
b) ;
我发现的是“无方法”错误。
我正在这样做:
b) ;
没有图像上的“s”,然后我去“无方法图像”。
最新资料:
因此,在指挥线上,我跑了“铁路”进入奥塞莱,然后我用我的控制器操作Im的手法:
@articles = Article. where (article_type_id) => 5).order (“id DESC”).limit(5).joins (:image)
请允许我:
@articles = Article. where (article_type_id) => 5).order (“id DESC”).limit(5).joins (:image)
Article Load (11.5ms) SELECT `articles`.* FROM `articles` INNER JOIN `images` ON `images`.`association_id` = `articles`.`id` WHERE `articles`.`article_type_id` = 5 ORDER BY id DESC LIMIT 5
=> [#<Article id: 1102129, article_type_id: 5, year_article_id: 0, name: “Zombie 电影 Sites”, sub entitled: “Hollywood-inspired life tips forapas t.pubglulature_com_date:nil, author_id: 29, thumbnail_image_id: 12033473, article_image_id: 12033473, article_image_id: 12033473, is_archived: false, is_featured: realent, ispublished: real,date:date_en, pmto_#<Article id: 1102129, article_type_id: 5, year_article_id: 0, name: “Zombie 电影 Sites”, sub entitled: “Hollywood-inspired life tips forapas t.pubglulature_com_date:nil, author_id: 29, thumbnail_image_id: 12033473, article_image_id: 12033473, article_image_id: 12033473, is_archived: false, is_featured: realent, ispublished: real,date:date_en, pmto_#<Article id: 1102129, article_type_id: 5, year_article_id: 0, name: “Zombie 电影 Sites”, sub entitled: “Hollywood-inspired life tips forapas t.pubglulature_com_date:nil, author_id: 29, thumbnail_image_id: 12033473, article_image_id: 12033473, article_image_id: 12033473, is_archived: false, is_featured: realent, ispublished: real,date:date_en, pmto_#<Article id: 1102122, article_type_id: 5, old_article_id: 0, title: "Nude Vacations", subtitle: "These places to get naked around the world make for...", display_date: nil, author_id: 574, thumbnail_image_id: 12024629, index_image_id: 12024629, article_image_id: 12024629, is_archived: false, is_featured: true, is_published: true, date_to_show: "2011-09-23 00:00:00", off_the_path: false, created: "2011-09-23 13:13:41", modified: "2011-10-18 10:44:15", fact_check_date: nil, unpublish_date: nil, is_qsfeatured: true, featured_order: 2, slug: "nude-vacations">, #<Article id: 1102122, article_type_id: 5, old_article_id: 0, title: "Nude Vacations", subtitle: "These places to get naked around the world make for...", display_date: nil, author_id: 574, thumbnail_image_id: 12024629, index_image_id: 12024629, article_image_id: 12024629, is_archived: false, is_featured: true, is_published: true, date_to_show: "2011-09-23 00:00:00", off_the_path: false, created: "2011-09-23 13:13:41", modified: "2011-10-18 10:44:15", fact_check_date: nil, unpublish_date: nil, is_qsfeatured: true, featured_order: 2, slug: "nude-vacations">]
因此,尽管如此,图像数据没有显示。
最新资料:
Huh,现在我看到,在这一街区,我getting在铁路上,我看到每条都在退回3次。
Article id: 1102129, article_type_id: 5, year_article_id: 0, name: “Zombie 电影 Sites”, sub entitled: “Hollywood-inspired life tips forapas t.pubglulature_com_date:nil, author_id: 29, thumbnail_image_id: 12033473, article_image_id: 12033473, article_image_id: 12033473, is_archived: false, is_featured: realent, ispublished: real,date:date_en, pmto_
,
,
因此,由于有3个图像协会,我收到3篇文章,但我没有图像。 这是两个世界中最糟糕的情况。
对图像进行单独查询比较容易。
最新资料:
这给我带来了我希望的东西,但我看不出,我似乎无法把这变成一个铁路点:
SELECT articles.title, articles.subtitle, images.url, images.caption
FROM articles
JOIN images ON articles.id = images.association_id
WHERE images.type= Thumbnail
ORDER BY articles.id desc
LIMIT 5 G
最新资料: