Create a doctrine repository class without an entity - doctrine-orm

I'm currently in a situation where I need to create a Repository class which would contain multiple financial statistic queries. The queries are not exactly tied up with one Entity but rather with multiple Entities and will select specific data from the database, based on various some conditions.
Having said that, I'm looking for a way to create a Repository class (i.e. StatisticsRepository) which is not associated with an Entity at all, so I could store the queries there. Simply creating that repository doesn't seem to be working. I'm guessing I probably need to create a service of some kind that loads this repo class? Is this correct, and if so is there an example I'm missing in the Symfony/Doctrine docs?

You can just create a class like StatisticsService/StatisticsFinder (naming convention is for you).
That service should have an entity manager injected, so define it in your config.
Create a query builder inside that service, then simply get and return results.

Related

BigQuery How to remove inherited access to a dataset

I have been providing access to datasets in BigQuery using the Share Dataset option for some time now. No problem.
But now, I have a specific requirement: I need to provide access to specific people/account/group but I don't want inherited access to work on this dataset.
I mean, I really need to provide access only to specific people to this dataset, so that not even inherited access work.
Is that possible? And if so, how can I do that?
To add more context. There is a dataset which should be available only for one Service Account (the one populating it) and some specific consumer account (HR) as it will contain sensitive data.
Problem is that our project already contains a couple of BigQuery Admin accounts and they of course inherit permissions over the dataset.
I don't think it would be possible as Project level roles are inherited automatically. Making new project may be helpful.

Loopback default values for missing properties when fetching data from MongoDB

How should I define the Loopback model so that all the properties listed in the model JSON file would always appear on the result even when those properties have no value (or are missing) from the MongoDB record? Should this behaviour be configured in the Loopback or in the MongoDB?
Thanks!
MongoDB is a Schema-less database. It is designed in this way to give us flexibility for adding new fields to a document without any need to restart the database. So I don't think that it is a good idea to handle this scenario on the database side.
I think the best way to handle this could be setting a default value for every property in LoopBack model definition. This solution has a problem when some data is inserted into the database from outside the project.
You can also handle missing parameter at the front-end side.
Another solution that I can think of, is implementing an afterRemote method for checking the existence of all the fields. In this case, you can use this function after any API route that you want to. You can check the following link for more information:
https://loopback.io/doc/en/lb3/Remote-hooks.html#signature

Loopback: How to isolate a users queries to a specific datasource?

Let's say I have two users, A and B, with IDs 1 and 2 (respectively). Further, let's assume I have two datasources configured: X and Y.
How could I isolate ALL queries issued by user A to datasource X, and all by B to Y for some given remote method? For example, say that A wants to run 'find' for some model via the API - how could I make sure that the only results A will get are those which are accessible through datasource X?
I'm not sure I entirely understand why you would decide a datasource based on the current user, but in any case, I'm not sure you can do that with LoopBack ... at least, not easily. LoopBack is a model-driven framework - everything derives from the model. As such, all API endpoints go through a model (although you can set up custom routes). And each model is connected to a single datasource.
So, if I hit /api/Widget/13 there is no way to make that findById() call switch between two datasources, it will always hit whatever datasource the model is connected to.
Okay, that all said, the solutions I see are to:
Create a "dispatcher" and have that model do the appropriate thing.
Create a custom remote method on your existing model and do the decision making there and the find, etc on the correct datasource.
In either case, it's not straightforward, and not built-in. FYI, if you need to get the datasource you can access it from the LoopBack application object: MyModel.app.datasources.ds1

Retrieving related data using edmx and repository pattern

I am writing a simple mvc application with edmx and repository pattern.
I have the following table structure.
1) Employee
ColumnName:Name,ProjectCode
2) Project
ColumnName:Code,ProjectName
There is only data relationship between these two table,no association is defined in database between them.
I have to display projectname in list view of Employee in place of projectcode. So I have retrieve ProjectName from Project table for every entry of projectcode in Employee.
I have already created a repository class for employee.
What is the best and easiest way implement this requirement? I would prefer not to create a repository for Project entity just for retrieving ProjectName column value for provided code.
You can use Generic Repository pattern instead of creating each of repository.Using that either way you can query the context and navigation property do the rest of the things for you.
Following links will explain the implementation of generic repository pattern.
Here
Here

Entity Framework 4.1 RC POCO - Unit Test the name of produced field names

Is it possible to access metadata about a POCO entity using EF4.1 that states what the database field names are? Most importantly on foreign key values.
I would like to access this for the purpose of unit testing whilst trying to apply EF4.1 to an existing database schema. I cannot change the existing column names.
Currently the tests create the database using SQL Server Compact 4.0 so I can see the names of the fields, but it would be better if this was automated.
Pseudo code for a test being
Create entity
Save entity
Check that the field name is as expected
That is not unit testing. That is integration testing. Moreover such tests are not too much usefull. Don't let EF create database and instead use copy of the existing database. Simply save entity and load entity in a new context. If data are ok you are happy with it. You can make each test transactional so the transaction is rolled back after each test.
EF 4.1 with code-first approach doesn't offer access to metadata workspace. You can try to convert DbContext back to ObjectContext and try to access MetadataWorkspace:
ObjectContext ctx = ((IObjectContextAdapter) context).ObjectContext;
MetadataWorkspace workspace = ctx.MetadataWorkspace;
Searching anything in MetadataWorkspace is terrible experience. That class is definitely not designed to be used in custom code.