Awesome. That's exactly what I want. I thought I tried this, but maybe it wasn't exactly the same. Thanks!

On 7/14/06, Ayende Rahien < [EMAIL PROTECTED]> wrote:

What are you trying to do?

I.e: Are you trying to get all Accounts in that date, regardless of them having valid transactions in this date or not?

 

If that is what you are trying to do, consider using this:

 

select a,t from Account a left join fetch a.Transactions t

where a.Activation between ? and ?

   and t.EffectiveDate between ? and ?

 

Note that you will get duplicate accounts, if the account has more than one transaction in that date, and that the return value is an array of arrays, like this:

 

{

                {account #1, null},

                {account #2, trans #434},

                {account #3, trans #445},

                {account #2, trans #887}

}

 

Notice that the Account #2 repeats.

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of Chris Bilson
Sent: Friday, July 14, 2006 11:12 PM
To: [email protected]
Subject: [Castle-users] What's the "Right Way" to load some of a lazy HasMany?

 

I have been struggling with this. None of the ways I can come up with seem to feel right:

 

[ActiveRecord] public class Account : ActiveRecordBase {

   [PrimaryKey] public int ID ...

   [Property] public string AccountNumber ...

   [Property] public DateTime ActivationDate ...

   [Property] public DateTime CloseDate ...

   [HasMany(typeof(FinancialTransaction), Lazy=true] public IList Transactions ...

 

   public static Account[] FindForDate(DateTime effectiveDate) {

     // TODO: Get all Accounts that were active on effectiveDate, and all the

     // Transactions for each one, that happened on that date.

  }

}

 

[ActiveRecord] public class FinancialTransaction : ActiveRecordBase {

   [PrimaryKey] public int ID ...

   [Property] public TransactionCode TransactionCode ...

   [Property] public decimal Amount ...

   [Property] public DateTime EffectiveDate ...

 

   public static FinancialTransaction[] FindForDate(DateTime effectiveDate) {

      // Here's how I get transactions that happened on a date:

      return (FinancialTransaction[]) FindAll(typeof(FinancialTransaction),

         _expression_.Between("EffectiveDate", effectiveDate.Date,

            effectiveDate.Date.AddDays(1)));

   }

}

 

So, for Account::FindForDate i've tried HQL like:

 

select a from Account a join fetch a.Transactions t

where a.Activation between ? and ?

   and t.EffectiveDate between ? and ?

 

But apparently, that only returns Accounts that have transactions in that date range.

 

I tried several other things, gave up, and just had the calling code call Account.FindForDate, followed by FinancialTransaction.FindForDate, and then manually stitch them together. I remember doing this before, several months ago, and it worked, but now I can't find the code I used. Doh!

 

Anyway, does anybody have any tips, opinions, best practices for getting some children but not all, and having them linked to the correct parent object. Thanks!

 

--Chris Bilson



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


_______________________________________________
CastleProject-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/castleproject-users





--
--c
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
CastleProject-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/castleproject-users

Reply via email to