@@ -117,7 +117,7 @@ class HasMany
117117 struct Loader
118118 {
119119 std::function<size_t ()> count {};
120- std::function<void ()> all {};
120+ std::function<ReferencedRecordList ()> all {};
121121 std::function<void (std::function<void (ReferencedRecord const &)>)> each {};
122122
123123 std::weak_ordering operator <=>(Loader const & /* other*/ ) const noexcept
@@ -150,7 +150,7 @@ template <typename OtherRecord>
150150inline LIGHTWEIGHT_FORCE_INLINE void HasMany<OtherRecord>::RequireLoaded()
151151{
152152 if (!_records)
153- _loader.all ();
153+ _records = _loader.all ();
154154}
155155
156156template <typename OtherRecord>
@@ -239,28 +239,40 @@ template <typename OtherRecord>
239239inline LIGHTWEIGHT_FORCE_INLINE HasMany<OtherRecord>::iterator HasMany<OtherRecord>::begin() noexcept
240240{
241241 RequireLoaded ();
242- return _records->begin ();
242+ if (_records)
243+ return _records->begin ();
244+ else
245+ return iterator {};
243246}
244247
245248template <typename OtherRecord>
246249inline LIGHTWEIGHT_FORCE_INLINE HasMany<OtherRecord>::iterator HasMany<OtherRecord>::end() noexcept
247250{
248251 RequireLoaded ();
249- return _records->end ();
252+ if (_records)
253+ return _records->end ();
254+ else
255+ return iterator {};
250256}
251257
252258template <typename OtherRecord>
253259inline LIGHTWEIGHT_FORCE_INLINE HasMany<OtherRecord>::const_iterator HasMany<OtherRecord>::begin() const noexcept
254260{
255261 RequireLoaded ();
256- return _records->begin ();
262+ if (_records)
263+ return _records->begin ();
264+ else
265+ return const_iterator {};
257266}
258267
259268template <typename OtherRecord>
260269inline LIGHTWEIGHT_FORCE_INLINE HasMany<OtherRecord>::const_iterator HasMany<OtherRecord>::end() const noexcept
261270{
262271 RequireLoaded ();
263- return _records->end ();
272+ if (_records)
273+ return _records->end ();
274+ else
275+ return const_iterator {};
264276}
265277
266278} // namespace Lightweight
0 commit comments