Someone can tell me why the condition for the “Profiles” table is not running. How can I access the “CommentArticles” table provided in the “Profiles” table. Thanks!
Can you explain your database schema a bit so we can understand what the relations are supposed to be? In general, your conditions would only make sense when defining an association between the two tables in question (Profiles and CommentArticles in this case), but the code here is defining associations between Blogs and CommentArticles, and between Blogs and Profiles, not between Profiles and CommentArticles.
Thanks Zuluru for read my message.
Exactly… the code here is defining associations between Blogs and CommentArticles, and between Blogs and Profiles. The question is how to create a condition for profiles with CommentArticles in same file.
CREATE TABLE blogs (
id bigint NOT NULL,
title text,
comment_article_id bigint NOT NULL
);
CREATE TABLE comment_articles (
id bigint NOT NULL,
profile_id bigint NOT NULL,
name varchar(255)
);
CREATE TABLE profiles (
id bigint NOT NULL,
name varchar(255)
);
Based on this, it seems that there is no direct relation from profiles to blogs. There is a relation from profiles to comment_articles, and from comment_articles to blogs. Is that correct? And you’re trying to figure out how to read a blog record with it’s associated comment_article, and that comment_article’s associated profile?
What you need, then, is an association with CommentArticles in your BlogsTable, and an association with Profiles in your CommentArticlesTable. Do you know about the bake tool? If you use that, it’ll generate a lot of this stuff for you automagically based on your database schema.