Has_many with nullable foreign_key?

Is there a way to use has_many and have it operate like such?

select * from pages where site_id = #{id} or site_id is null

I know there’s finder_sql, but then I’ll lose the find_in_collection


something like:

@pages = Page.find :all, :conditions => [“site_id = ? OR site_id is

:conditions takes a string for the SQL WHERE condition. The array i use
there, handles the espacing of the “id” value to prevent SQL injection,
and then replaces “?” with the escaped value of id…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs