I am creating a market plus system. There are two different identities - a customer and a seller . I have the following tables- users, products and sellers. On registration all the data is getting stored in users table with the role as a customer or as a seller and if seller its email is even stored in the sellers table having two more columns of market and city. On logging in as a seller i am asking for market and the city and it is also getting stored and after it i am asking for adding the product details. On logging in as a customer i am asking for the market and city and i am able to fetch those emails of the sellers with the same market and city but after that i am unable to fetch the data from products table with the same email whose market and city are same as customer's market and city. Why so ??
This is my customer controller-
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Seller;
use App\Product;
use DB;
class Customercontroller extends Controller
{
public function customerdata(Request $request)
{
$c_market=$request['c_market'];
$c_city=$request['c_city'];
$data=DB::table('sellers')->get();
$pdata=DB::table('products')->get();
$eml=DB::table('sellers')->select('email')->where(['market'=>$c_market,'city'=>$c_city])->get(); //This is working
$p=DB::table('products')->select('product')->where(['$pdata[0]->email'=>$eml])->get();
dd($p); /*But on doing this i am getting an error of Object of class stdClass could not be converted to string*/
}
}
In your code $eml is an object. So when you are using it in the where clause as a string, the error is occurring.
You can get the desired result by using join clause.
DB::table('sellers')
->leftJoin('products', 'products.email', '=', 'sellers.email')
->where('sellers.market', $c_market)
->where('sellers.city', $c_city)
->get();
This will give you all the products related to inputted market and city.
Related
I am working in Dynamo DB for the first time . My assignment is Ticket Management System where it has 3 entities Department , User and Ticket. The relationship between each entity is.
I have identified the following access patterns
Fetch a Department.
Fetch all users in Department
Fetch a given user in Department
Fetch all Tickets belongs to the Department
Fetch all Tickets assigned to the User
for which i defined the following data model . I am thinking of creating GSI with Tickets as PK and User as SK to do 4 & 5
On a higher level I need to perform 2 updates . I can update the User to which the ticket is assigned and I can update the ticket status as inprogress, resolved . And in the table I have Ticket details as JSON object as below.
I need help from from the experienced people whether my understanding and approach is efficient.
I think you're on the right track. I'd design it as a table with two Global Secondary indexes. The base table looks like this:
The first Global Secondary Index like this (GSI1):
The second Global Secondary Index like this (GSI2):
Now for the why:
This design allows you to easily update the following things:
A user's department
A ticket's status if you know the ticket Id
A ticket's user if you know the ticket Id
A ticket's department if you know the ticket Id
You can get a bunch of information from this model:
Fetch a Department.
Query the base table with the department name or list all departments
Fetch all users in Department
Query GSI 1 with the Department Name and filter the sort Key using begins_with = USER#
Fetch a given user in Department
Sound like you know the UserId, so do a GetItem on the base table. If that's not the case, do the query mentioned in "Fetch all users in Department".
Fetch all Tickets belongs to the Department
Query GSI 1 with the department name as the PK and filter the SK using begins_with = Ticket#
Fetch all Tickets assigned to the User
Query GSI 2 with the user id as the PK and filter the SK using begins_with = Ticket#
good day guys,
I need your opinion on this problem. although am using Django for my project but am sure this problem is not tie to django alone. So, I am working on these services booking system. In my database I have 3 tables listed below:
User_Table with field
• Id
• Username
• Fullname
Services_Table with field
• Id
• name
• Price
Transaction_Table with field
• Id
• User_id
• Services_id (many to many relationship)
When this services get booked, I send it to the transaction table using the user_id and services_id as foreign key for User Table and Services Table meaning it’s the id values that are saved.
When a client want to view his or her transaction history, I provide it by running the query:
price = transaction.service.price
service_name = transaction.service.name
total_cost = sum of all services selected
as not to present the user with id values for price and service_name.
now here is my problem, in future, if the admin decide to change the name and price of a service and the client goes back to view his old transaction log, the new value get populated cus I referenced them by ids which is not what I want, I want the client to see the old value as a receipt would be even when I updated the services table.
What do you suggest I do in this case?
You should record every transaction made and record the price and amount it totalled up to at the moment the txn was made. Transaction model should have fields to record every detail about the transaction.
This means:
You would have a txn_service table, where all services in a transaction are saved and linked to the transaction table.
I have a column named company ID that contains various comapnies with differnet employes in them, I need a DAX Query which will give data A/Q to the Company id, suppose if there are 3 employes inside a company and each of them have a companyid 1 then I they should able to see the reports of each other but they cannot be able to see the reports of comanyid 2 and 3, how this can be achived?
I know I can do this by creating different Roles for each companyid, but how can this be achived if I want this to be built in one particular role???
What you are asking is to implement Dynamic Row Level Security.
Model:
User Table: Table that contains user detail along with the field on which we will apply security(here email field).
Company Table: Table containing company data .
User Company Bridge: Bridge table that contains permission details, for example user x is member of company y and z.
Company Data Table: Measures or transaction information of company that is to be filtered.
Defining RLS(Row Level Security):
In Modelling -> Manage Roles, create a new role on Email of User Table by this DAX query which returns the email id of logged in user.
[Email] = userprincipalname()
Finalizing:
Go to PowerBI Service -> Dataset -> Security and add users to the roles created.
To test the implementation:
Go to Modelling tab of pbix file.
Click on View As Roles.
Check other User checkbox and put an email ID and also check Profile
checkbox.
Now you can see data filtered.
In this manner it becomes easy to maintain roles and security by just modifying the bridge table that stores all permission details.
I create a ticket for a custmer from LDAP datasource,customer_id and customer_user_id column in ticket table show like below:
customer_id customer_user_id
zhangjq#**.com zhangjq
I think this is the foreign key which OTRS use to associate this ticket with an customer in LDAP,But,When after I update the value of customer_id and customer_user_id column,the customer info also displayed correctly in ticket view page:
Customer Infomation
Firstname: Junqian
Lastname:Zhang
login:zhangjq
Email:zhangjq#**.com
Comment:##2012.09.03
All of these information is read from LDAP.
So,how does otrs save relation between ticket and ldap customer in DB table? or OTRS has other way to manage the relation between ticket and ladp customer?
When setting up your LDAP-Connection for CustomerUser, you can define a CustomerKey. This is the key, OTRS is using to uniquely identify a customer.
When after I update the value of customer_id and customer_user_id column,the customer info also displayed correctly in ticket view page
What are exactly doing? If you are modifying in the SQL-Database, this won't have any impact on the data displayed within OTRS, as this data is cached.
If you are doing modifications in your LDAP, this won't change anything either of the customer-information displayed as this data only gets updated when you (re-)assing a customer to a ticket.
I have a models in Django that are something like this:
class Classification(models.Model):
name = models.CharField(choices=class_choices)
...
class Activity(models.Model):
name = models.CharField(max_length=300)
fee = models.ManyToManyField(Classification, through='Fee')
...
class Fee(models.Model):
activity = models.ForeignKey(Activity)
class = models.ForeignKey(Classification)
early_fee = models.IntegerField(decimal_places=2, max_digits=10)
regular_fee = models.IntegerField(decimal_places=2, max_digits=10)
The idea being that there will be a set of fees associated with each Activity and Classification pair. Classification is like Student, Staff, etc.
I know that part works right.
Then in my application, I query for a set of Activities with:
activities = Activity.objects.filter(...)
Which returns a list of activities. I need to display in my template that list of Activities with their Fees. Something like this:
Activity Name
Student Early Price - $4
Student Regular Price - $5
Staff Early Price - $6
Staff Regular Price - $8
But I don't know of an easy way to get this info without a specific get query of the Fees object for each activity/class pair.
I hoped this would work:
activity.fee.all()
But that just returns the Classification Object. Is there a way to get the Fee Object Data for the Pair via the Activities I already queried?
Or am I doing this completely wrong?
Considering michuk's tip to rename "fee" to "classification":
Default name for Fee objects on Activity model will be fee_set. So in order to get your prices, do this:
for a in Activity.objects.all():
a.fee_set.all() #gets you all fees for activity
There's one thing though, as you can see you'll end up doing 1 SELECT on each activity object for fees, there are some apps that can help with that, for example, django-batch-select does only 2 queries in this case.
First of all I think you named your field wrong. This:
fee = models.ManyToManyField(Classification, through='Fee')
should be rather that:
classifications = models.ManyToManyField(Classification, through='Fee')
as ManyToManyField refers to a list of related objects.
In general ManyToManyField, AFAIK, is only a django shortcut to enable easy fetching of all related objects (Classification in your case), with the association table being transparent to the model. What you want is the association table (Fee in your case) not being transparent.
So what I would do is to remove the ManyToManyField field from Activity and simply get all the fees related with the activity. And thenm if you need a Classification for each fee, get the Classification separately.