There will be an "Account" which can be a "Customer" or a "Supplier", or both. It has to be one of them at-least.
I am wanting to use Class Table Inheritance but I'm unsure whether I will be able to have an Account that can be both a Customer and a Supplier.
Can anyone confirm?
I would appreciate any help.
I don't think STI is the right choice for your problem since it's more like a many-to-many relationship.
You're question is a little too broad to give you exact answer. Depending on your need you may have a few options.
For example, if being Customer/Supplier means to have additional data, it would be better to make them a separate entities with relationship to the Account. So in your app, you would recognize if an Account is a Customer or Supplier by checking if appropriate related entity exist. So it you could explain it as
An Account can have Customer or Supplier profile
o something like this, instead of
Account can be a Customer or Supplier
Other solution would be to treat it as a simple ACL, where Account is a subject, and Customer and Supplier are roles.
I'ts hard to provide more detailed answer to your question.
Related
I am designing a database for a language learning center. I have 3 subjects to manage: admin, teacher and student.
Admin can assign the role to the other 2 objects
The teacher has the role of posting instructions on the website
Students can register for the course and pay
Should I create a teacher and a student table in the database? If so - how should I design them? Otherwise how should I manage just one user object?
I designed the AppUser class to inherit the identity user class, the student and teacher classes inherit from the AppUser class, is that a good approach?
A better solution is to create a teacher and a student table in the database. Because their roles are completely different, this can separate their respective businesses completely. Reduce the complexity of design.
Create a login page, you can provide a drop-down list for users to choose their own roles, query the database according to the user's role, and then fill the user and the user's role to identity to achieve authentication.
The question for how to handle this comes down to first separating logic into the "Can do" and "has a" bins.
If your objects have unique relationships, (Lets say Teachers have several Table relations unique to them), then you want to use different tables for them.
If however you can simplify the relations enough that they can be functionally the same (IE both Teachers and Students will have a Classroom relation, which though it means something different for them, can be re-used as the same column for both), then you want to instead handle this difference via Roles.
Roles allow you to apply authorization to various parts of your website.
It might also be best practice to do both of the above.
When handling "multi user type" style interfaces, you typically will need to be careful about selecting how you register users. Do you want to do it via invitation emails/codes? Or perhaps Administrators create the users by hand and there is no form of registration at all?
You can use AspNetRoles table. And bind it to AspNetUsers table. You don't need to create teacher and students table.
I'm building a repository where Teachers ans sutendts will post their academical work. I need a way to make each teacher (role: editor) responsable to moderate and aprove their students (role: author) content.
There is a way to links these kind of user relation?
Not really in users directly, as there is no such relation as "User owning users".
Roles is the way to go if the groups not change too much, but you are going to need to define a different role to group students for every teacher, and properly getting out of that role students no more assigned to that teacher.
It could be more easier to maintain two roles, teachers and students, and with user_meta validate if the student is currently overseen by the teacher and therefore is able to handle student's posts.
The specifics are very difficult to write down here unless you have already defined how do you want to proceed. The plugin recommended in the first comment requires no code but maintenance by hand of roles for every user.
I am using FOSUserBundle in my Symfony2 project.
My goal is to make the teams consist with multiple users. Users are invites by administrator (owner) by e-mail confirmation.
If a user belongs to one team, can't set up new accounts using the same address. Of course, each user should have the opportunity to unsubscribe from the team.
Are there any ready-made solutions? I looked for Groups With FOSUserBundle.
Or do you have any good advice?
You were right, groups can be a good ready-to-use solution to make your logic.
The association is already setup and it's also easy to extend.
The documentation (now part of Symfony's doc) contains a great guide to use groups.
Of course, you can make your own entity, take example from the FOSUB User->Group logic (association) .
You should see the Security and Roles part of the documentation to manage authorisations of your different kind of users.
You can assign roles to your different groups, and make your users directly inherit the roles of their group for manage access permissions.
For the confirmation email, see the corresponding documentation too .
And for the unsubscribing, just remove the association between the user you want remove from a Group and the Group (or Team).
This is also part of the association, see the doctrine documentation.
Good use.
i have this project where i have an issue, there are 3 relevant enteties.
User:
has_many: Leads
Bot:
has_many: Leads
Lead:
has_one: User/Bot
Now, a user and a bot share a lot of the same things, but they use different firewalls, they have many different fields etc, but i want a user and a bot to be interchangeable in regards of who a lead belongs to, it can either belong to a bot or a user, never both at the same time.
And in many of my other enteties where i run stats etc, i refere to a single field, i dont check if there is a user or a bot.
Is it possible to make these 2 enteties share the same Primary key and then just somehow refer to a single entity in the Lead field ?
Or what would be the best design approach in Symfony?
If you have all fields the same in 2 entities I would recommend you to drop Bot entity at all. All you need is just one field type with available values bot and user. To optimize SQL queries I would recommend you to declare this field as ENUM type.
Also if you really need different entities you can use Single table inheritance with discriminator field type described above.
I have two entities (user and Company). I must set up an mail system, each user can send messages to another user or to a company, and the same for the the companie.and i have to displays messages exchanged in form of conversation. can I implement this with Doctrine2 and Symfony2?
Explaining the whole structure on how to do it is a little bit to complicated...BUT
I think what you looking for is a usable data-structure... and for this you will need a manyToMany relation with extra columns, please take a look at the following links I hope this will give you an idea on how to manage your data:
http://future500.nl/articles/2013/09/doctrine-2-how-to-handle-join-tables-with-extra-columns/
http://future500.nl/articles/2013/09/more-on-one-to-manymany-to-one-associations-in-doctrine-2/