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
CastleProject-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/castleproject-users

Reply via email to