The Heap™ – Consultancy ©®

General on- and off-site discussion for dba.stackexchange.com....
Jun 30, 2020 17:37
yeah, that is also why I wasn't sure what to follow because EF doesn't allow to certain degree of complexity, depending on how complex u make you might have to add other tables into play to extend it
Jun 30, 2020 17:30
will do thanks
Jun 30, 2020 17:21
thanks a lot guys I will look into those examples and see what i can come up with
Jun 30, 2020 17:20
but it still haven't clicked
Jun 30, 2020 17:20
and then they explained to me that account is actually a category with sub category that represents things like asset, expense etc that htye use in place of the customer in some scenarios
Jun 30, 2020 17:19
I swear I was thinking account would be a bank account or payment method linked to the customer
Jun 30, 2020 17:19
this accounting stuff is hard
Jun 30, 2020 17:19
yeah I will try those thanks, I think my biggest confusion is not even the SQL but what the heck account really is ahaha
Jun 30, 2020 17:18
yeah I see it now, it uses a intermediary table? to link everything and also gives u what is what
Jun 30, 2020 17:16
mmm maybe I didnt understood the implementation there let me read it again
Jun 30, 2020 17:15
but the link u sent me the accepted answer was not like that
Jun 30, 2020 17:14
sure
Jun 30, 2020 17:14
honestly I am having a hard time understanding it myself because I am not very knowledge in accounting
Jun 30, 2020 17:14
they can't, because account is an entity and customer is another they share the same space but they are not the same thing in accounting
Jun 30, 2020 17:12
but never both
Jun 30, 2020 17:12
I think this would work but I am not sure if this is a good way? basically customerId or accountId could be null
Jun 30, 2020 17:11
ops 1 mistake fixing
Jun 30, 2020 17:10
CREATE TABLE `accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `transactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customerId` int(11) DEFAULT NULL,
  `accountId` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Jun 30, 2020 17:03
ah no, I don't think so, let me write a SQL, I think this should be OK moment
Jun 30, 2020 17:00
I will check that thanks
Jun 30, 2020 17:00
@AndriyM "one at a time" would that mean having 2 fks while one is always null and the other not?
Jun 30, 2020 16:59
@CadeRoux the thing is in accounting the definition of account is different, its not a say bank account or anything so I can't link it like that
Jun 30, 2020 16:22
rrr sorry that is code first using EF, it would translate into something like this in short
id primary key
total decimal
customerId fk to customer
accountId fk to account
Jun 30, 2020 16:12
and transaction will be either paid by an account or an customer
Jun 30, 2020 16:11
I honestly don't know how it should be written is what I am trying to get at... because Account and Customer are so different in what they are
Jun 30, 2020 16:11
and querying it later would probably be a nightmare?
Jun 30, 2020 16:10
because either account or customer will be null
Jun 30, 2020 16:10
public class Transaction
{
    public int Id {get;set;}
    // other properties of transaction
    public decimal Total { get; set; }
    public int CustomerId { get; set; }
    public virtual Customer Customer { get; set; }
    public int AccountId { get; set; }
    public virtual Account Account { get; set; }
}
Jun 30, 2020 16:10
@AndriyM In fact I haven't, I can't decide how it should be written, what i meant with that is that I don't think say this is right:
Jun 30, 2020 15:50
Hello everyone, I would like some assistance in understanding how should I make this tables, its related to accounting which is not really my field and is making my head spin.

I have an Order, this order produces 2 transactions one that gives positive balance and another that gives negative balance.

On the transactions I have say paid to and paid from, this can be from a customer or an account(account here is merely a category/ledger say Asset, Liabilities, Equity, Income, Expsenses) while customer is an actual customer
Oct 4, 2017 14:13
@MDCCL thanks I will look at that, ypercubeᵀᴹ did help me a good deal with his sample I think I was mainly too focused on the definition of session it self
Oct 4, 2017 13:39
@ypercubeᵀᴹ alright thanks a lot it has already helped me seeing how to go about it
Oct 4, 2017 13:36
rrrr how do I reply to a message while having formatted code in it lol, its breaking making the :id as string instead of linking, oh well too late to edit it again
Oct 4, 2017 13:35
no nvm I misunderstood it, `package_details` that looks great. So if I had to query the user to know if he have a session open to use what it would look like? something like this?

SELECT ...
FROM licenses l
LEFT JOIN package p
ON p.package_id = l.package_id
LEFT JOIN package_details pd
ON p.package_id = pd.package_details
WHERE l.expire_data <= NOW() AND
pd.in_use = 0 AND
pd.product_id = XYZ
Oct 4, 2017 13:27
@ypercubeᵀᴹ I like your design but wouldn't I lose a way to tell how many sessions product A can run on a package, since you are defining a maximum amount of sessions for the package and not for a specific product if I got it right
Oct 4, 2017 13:20
@ypercubeᵀᴹ done and thanks for the answer reading now :)
 

 Ask a Super User Moderator

For moderation, spam, troublesome users and related issues you...
Sep 10, 2018 18:18
Is there a case where you would have to down clock your CPU to use it with certain memories specs? say if I have a 8700k and get a 2x8gb 2400mhz ddr4
 
Oct 10, 2017 00:21
I was wondering if this query is fine as is or could be optimized, and if everything else looks fine, on the live sample I filled the minimum required to get it all working hope I did it all right... I haven't setup any indexes yet as this was just for testing purposes for now.
Oct 10, 2017 00:19
Oct 10, 2017 00:19
SELECT SUM(pd.max_sessions)
  FROM mybb_store_licenses l
LEFT JOIN mybb_store_packages p
       ON p.id = l.package_id
LEFT JOIN (SELECT *
             FROM mybb_store_package_details
		  ) pd
	   ON pd.package_id = p.id
    WHERE l.ts_expire >= NOW() AND
          pd.product_id = 34;
Oct 10, 2017 00:19
@ypercubeᵀᴹ hey, if you have some time, would you mind taking a look here?
Oct 4, 2017 13:54
I see, thanks a lot, for taking the time, to explain it and make the sample.
Oct 4, 2017 13:46
I guess I would need a new table for that?
Oct 4, 2017 13:46
they are user sessions in this case, yes
Oct 4, 2017 13:44
yes, correct
Oct 4, 2017 13:43
I though the above query would be closer to that?
Oct 4, 2017 13:43
but the user can buy different packages multiple times, so I need to be able to access the amount of sessions he still have that is not in use for a given product, that hasn't expired of course hehe
Oct 4, 2017 13:43
From my understanding your proposed layout, I would have packages for single products and packages for multiple products right? And I can define the maximum sessions per products on the details
Oct 4, 2017 13:41
OK, now it formatted lol but if I try to reply to your answer with it, it breaks the "reply to" by adding spaces in front of it
Oct 4, 2017 13:40
   SELECT ...
     FROM licenses l
LEFT JOIN package p
       ON p.package_id = l.package_id
LEFT JOIN package_details pd
       ON p.package_id = pd.package_details
    WHERE l.expire_data <= NOW() AND
          pd.in_use = 0 AND
          pd.product_id = XYZ