I have a problem with grocery CRUD and "set_relation_n_n" function:
http://www.grocerycrud.com/documentation/options_functions/set_relation_n_n
I want the fields from "This Table", "Relation Table" and "Selection Table". There are any way to do that?. This is my schema (MySQL):
EDITED:
A few things (by the moment):
This table: timeline_events;
Relation table: timeline_events_options;
Selection table: timeline_events_tags;
id_timeline is the foreign key from another table (not showing in the image above), event_id is a field required for the widget I am using now. id_event is the foreign key from timeline_events, id_event_tags is the foreign key from timeline_events_tags.
Thank you very much for your answers :).
I believe you should repair your tables first. All three tables has primary key named id which could be id_timeline in timeline_events table; id_event in timeline_events_options table and id_tag in timeline_events_tags table. Considering this as your table fields, this should be the function.
$crud->set_relation_n_n('eventtags', 'timeline_events_options', 'timeline_events_tags', 'id_timeline', 'id_tag', 'tags','priority');
I don't guaranty it will work because I didn't test it but you can try this one.
Related
My question is related to the ER-diagram I designed using Oracle SQL developer. I designed this ER-diagram but I don't know how to read the relationships between these tables.
I have created this ER diagram:
ER Diagram
As it can be seen that these relations don't look like those normal one to many or many to one relations. Can anyone please help me how to read the relation between SYS.GENERAL_LEDGER_ACCOUNTS and SYS.INVOICE_LINE_ITEMS? Thanks in advance
The relationship is described by the foreign key:
ALTER TABLE invoice_line_items
ADD CONSTRAINT line_item_fk_accounts
FOREIGN KEY (account_number)
REFERENCES general_ledger_accounts(account_number);
Defines a foreign key with the name line_item_fk_accounts on the column account_number which references the account_number of the general_ledger_accounts.
Assuming that it is notNULL then this is a many-to-one relationship such that each row of invoice_line_items has a relationship to exactly one row in the general_ledger_accounts and there can be many invoice_line_items for each general_ledger_accounts.
Similarly, line_items_fk_invoices is a many-to-one constraint with many invoice_line_items each referencing one row of the invoices table.
Aside: NEVER modify the system schemas. If you do you risk making the database unusable and invalidating any support contract that you have with Oracle. Instead, you should create a user and then work in that schema.
I have a table cars with attributes: id, name. I also have another table specs with id, car_id, name. This tables are related with one to many relations from the Models. I also have set up the foreign keys in.
I have a controller manageData where i have a function insertCar which i use to insert data and update both tables. I wan to create another function deleteCar from where i can delete the car along with its specs from the other table
Use onDelete() method in migration when defining foreign key:
$table->foreign('car_id')->references('id')->on('cars')->onDelete('cascade');
In this case when you'll delete a car record, related data will be automatically deleted from another table.
https://laravel.com/docs/5.4/migrations#foreign-key-constraints
I read that we cannot create a primary key on a column in a Hive table. But I saw the below DDL in some other place and executed it. It worked without any problem.
create table prim(id int, name char(30))
TBLPROPERTIES("PRIMARY KEY"="id");
After this I executed "describe formatted prim" and got to see that a key is created on the column ID
Table Parameters:
PRIMARY KEY id
I inserted two records with same ID number into the table.
insert into prim values(1,'ABCD');
insert into prim values(2,'EFGH');
Both the records were inserted into the table. What baffles me is that we cannot give the PRIMARY KEY in the create statement which I can understand, but when given in TBLPROPERTIES("PRIMARY KEY"="id") how different is it to the primary key in RDBMS.
PRIMARY KEY in TBLPROPERTIES is for metadata reference to preserve column significance. It does not apply any constrain on that column. This can be used as a reference from design perspective.
Can we use select statement when we declare a check constraint
create table category
(id_category number primary key,
category varcahr2(100) check (category in (select * from table1))
thank you
No, you can't.
I'm not sure that I understand what you are trying to accomplish. If you are trying to verify that the category exists in table1, assuming that category is the primary key of table1, you'd want a foreign key constraint not a check constraint. It would seem very odd, though, for there to be a category table where the category referenced a different parent table (presumably the category table defines the valid categories). Perhaps you want to define a unique constraint to ensure that there aren't duplicate category values in the table. Perhaps you're trying to do something else-- explaining the business problem will help us understand the proper way to model the issue.
I have 2 tables in my database that I'm trying to create Linq2Sql entities for. There's more to them than this, but this is essentially what they come down to:
Rooms UserActivity
-------- --------
RoomID ActivityID
RoomID (foreign key on Rooms.RoomID)
The UserActivity table is essentially just a log for actions a user performs against the Rooms table.
Since the UserActivity table is only used for logging actions taken, it didn't make a lot of sense (to me at least) to create a primary key for the table originally, until the Linq2Sql mapper refused to make UserActivity a part of the Room entity in my Linq entities. When I set up the entities in the Visual Studio designer, I got these 2 warnings:
Warning 1 DBML1062: The Type attribute 'UserActivity' of the Association element 'Room_UserActivity' of the Type element 'Room' does not have a primary key. No code will be generated for the association.
Warning 2 DBML1011: The Type element 'UserActivity' contains the Association element 'Room_UserActivity' but does not have a primary key. No code will be generated for the association.
These warnings led me to create the ActivityID column in my table as displayed above.
What I'd like to know is if there is any way to allow Linq2Sql to create relationships between my entities without having a primary key in both tables. If I don't have the primary key in the UserActivity table, the entities can still be created, but the relationships aren't generated.
Is is it possible to do this, or should I try to make sure my tables always have a primary key in them as a general good practice?
Any table that stores real data in your app should always have a primary key - most cases, in SQL Server environments, a INT IDENTITY(1,1) will be just fine. You don't have to keep track of those, no bookkeeping necessary etc. It doesn't cost you much, totally easy to do - I don't see any reason why not have a primary key, even on your UserActivity table.
ALTER TABLE UserActivity
ADD UserActivityID INT IDENTITY(1,1)
CONSTRAINT PK_UserActivity PRIMARY KEY
and you're done!
The only time I would say no primary key is needed is for things like temporary tables when bulk importing huge amounts of data, or other temporary scenarios.
Marc
You need a primary key to create relationships.
It's good practise to always design tables with primary keys, even if you add surrogate (auto increment identity).