From: Erik V. <eri...@xs...> - 2012-09-02 22:18:44
|
> However there is at least one use case with a disadvantage: > A general correction mechanism, which shows all portfolios containing one > type of items and allow moving back and forward between them. For this > use case a n:1 relationship complicates things a bit, but it is not impossible to > solve the issues. Money is not an item but an amount, I'd say. Nothing moves, just equal amounts get added and subtracted. To me, it's fundamentally different from all other Rails objects, and should be treated in its own way. > The code would be different however: > bankWallet = Wallet.create(bank, "wallet", Currency.class) > bankWallet.addOtherOwner(bank.getIpo()); > bankWallet.addOtherOwner(bank.getPool()); Indeed. > I am undecided, as it is possible to achieve the same result with a slightly > more complicated solution for the (special) Bank case. Your way, nothing should happen if a wallet gets a negative amount. You can no longer do this check at the lowest level, because the bank only breaks if the total amount of all its wallets becomes negative, not if any one of these does. So that kind of check must always be done at a higher (the owner's) level, as a separate action after each move at a lower level. Not sure how you are going to manage that. To prevent such complications, I'd rather have a little bit more complexity at a lower level (if needed at all, but I don't think so). Erik. |