Closed glamorous closed 14 years ago
Is rcc_users.newsitem_id
a valid column? What should it be joining on?
No, not a valid column, I have a column user_id in rcc_newsitems. But thinking about it, that should be named author_id I suppose and my code will work? Gonna give it a try tonight.
I suppose and my code will work?
I doubt it. For a start , surely the foreign_key is in this model? So the author field should be Belongs_to user? HasOne implies that there is a BenlongsTo field in the user model which seems completely wrong to me - a user doesn't belong to a news story, they have (presumably) many news stories so you need to change that for a start.
THEN if you use
'author' => new Field_BelongsTo(array(
'foreign' => 'user'
))
And your foreign key column in the newsitems
table is called author_id
it should work.
Wow, my relation is indeed wrong.. :( I read it wrong.. I read it as: "a newsitem hasone user instead of: "a newsitem belongsto an user and a user hasmany newsitems"
thanks for the info, I will try it tonight and close this when it works..
my column may still be named user_id and it worked!
I don't know if I did something wrong or if it's a bug but I have this code:
And it breaks on the load_with:
Unknown column 'rcc_users.newsitem_id' in 'on clause' [ SELECT
rcc_newsitems
.id
ASid
,rcc_newsitems
.date
ASdate
,rcc_newsitems
.name
ASname
,rcc_newsitems
.uri
ASuri
,rcc_newsitems
.body
ASbody
,rcc_newsitems
.status
ASstatus
,rcc_users
.id
AS:author:id
FROMrcc_newsitems
LEFT JOINrcc_users
ON (rcc_newsitems
.id
=rcc_users
.newsitem_id
) WHERErcc_newsitems
.status
= 'open' ORDER BYrcc_newsitems
.date
DESC LIMIT 3 ]So there's something wrong with what I did here:
Isn't this correct? Every newsitem has ONE author (= user)
Sorry if I did something wrong but there isn't much documentation about this :s