iboard/CBA — comment on commit 789d0537506d8cbc430d067d2ed4e1077164752a
File:  line 0
By iboard:

```
======= STEP 1 - START WITH ALL POSTINGS OF BLOG(self) ===========================
_postings = self.postings.unscoped
ANY_OF_DEBUG START WITH #BSON::ObjectId('4e1fc176f9110517c4000002')},
options: {},
class: Posting,
embedded: false> ============ OK ==============================================

======= STEP 2 - RESTRICT TO PUBLIC POSTS OR POSTS ADDRESSED TO OR OWNED BY USER==
_postings = _postings.addressed_to(_user.id) (((((1)
ANY_OF_DEBUG ADDED ADDRESSED TO #BSON::ObjectId('4e1fc176f9110517c4000002'),
"$or" =>[ {:recipient_ids=>nil},
{:recipient_ids=>[]},
{:recipient_ids=>[BSON::ObjectId('4ea7dafdf9110540a3000013')]},
{:user_id=>BSON::ObjectId('4ea7dafdf9110540a3000013')}
]
},
options: {},
class: Posting,
embedded: false> ============ OK Added "$or -> recipients" ====================

======= STEP 3 - RESTRICT TO !draft AND WITHIN GIVEN DATE-RANGE ==================
_postings = self.postings.published.online (((((2)
ANY_OF_DEBUG ADDED PUBLISHED ONLINE #BSON::ObjectId('4e1fc176f9110517c4000002'),
:is_draft =>false,
"$or" =>[
{:publish_at=>nil, :expire_at=>nil},
{:publish_at=>{"$lte"=>2011-12-30 18:40:02 +0100}, :expire_at=>nil},
{:publish_at=>{"$lte"=>2011-12-30 18:40:02 +0100}, :expire_at=>{"$gt"=>2011-12-30 18:40:02 +0100}},
{:publish_at=>nil, :expire_at=>{"$gt"=>2011-12-30 18:40:02 +0100}}
]
},
options: {},
class: Posting,
embedded: false> ........ OK - added is_draft and $or -> date-range
BUT- WHERE IS $or -> recipient_ids GONE ???????????????

((((1) scope :addressed_to, ->(user_id) { where.any_of(
{:recipient_ids => nil},
{:recipient_ids => [] },
{:recipient_ids => [user_id] },
{:user_id => user_id}

)
}
((((2) scope :published, -> { where(is_draft: false) }
scope :online, -> { any_of(
{:publish_at=>nil,:expire_at=>nil},
{:publish_at.lte=>Time.now(),:expire_at=>nil},
{:publish_at.lte=>Time.now(),:expire_at.gt=>Time.now()},
{:publish_at => nil, :expire_at.gt=>Time.now()}
)}
```