开发者

Polymorphic Association / Rails3 Question

开发者 https://www.devze.com 2023-02-06 18:34 出处:网络
Ok, I have a polymorphic Attachment model which is working okay when it\'s dependant of a Campaign model. This is working fine:

Ok,

I have a polymorphic Attachment model which is working okay when it's dependant of a Campaign model. This is working fine:

Campaign.last.attachments

I'm getting all the attachments of that campaign. But, I need to do it the other way around: Retrieve the parent object of an attachment (retrieve the campaign). I imagined it would be something like this.

Attachme开发者_高级运维nt.last.campaign

But I'm getting nil as result. The attachment object has attachable_id: 64, attachable_type: "Campaign".

I'm missing something here but I can't figure it out what.

Thank you!


If you configured the polymorphic association correctly:

some_attachment.attachable
0

精彩评论

暂无评论...
验证码 换一张
取 消