So in Django you can do this: unique_together = ('name', 'username',) so if you try to register people like this:
name: John, username: blabla <---- this gets registered
name: John, username: haha <---- this gets registered
name: John, username: blabla <---- this won't get registered because the combination of John and blabla already exists.
Is the something similar is Laravel I could use?
The main goal is to check if the name with the username exists together, if it does, throw back a validation error, otherwise register the record to the database.
edit #1: if I can get something like "unique together" in laravel, is it possible to modify the validation method based on a hidden field in the form?
For example I want the user to write their name and email and submit it, and have a checkbox. The checkbox would enable/disable the 'unique' check of the name, so like if I do this:
name: John Doe Corp. email: whatever, checkbox: Ticked
then it would check the 'name' column for duplicates.
Otherwise:
name: Jane Doe. email: whatever, checkbox: Not Ticked
then it would not check the name column for duplicates, allowing the record to be saved into the database.
Related
In Rails 4.2.11,
User.find_by(name: 'name', email: 'email')
is returning an ActiveRecord::Relation (containing array of one User instance) instead of one instance of User.
#<ActiveRecord::Relation [#<User id: 1, name: "Tester Test", email: "stester#xxx.xxx", created_at: "2021-04-27 14:08:49", updated_at: "2021-04-27 14:08:49">]>
This is happening in the context of a failing cucumber test where I create an authorization record and a user record. The authorization record is found, but the user record comes back only as a Relation no matter what I do. Tried .first, .take, several other ways to retrieve the instance.
This is identical to the output of User.where, not User.find_by. Any idea why this is happening???
And if you add '.first' like:
User.find_by(name: 'name', email: 'email').first
works for you?
Everything is working now, after I stopped running the test for about 10 minutes. My only explanation is that there sometimes seems to be a discrepancy between my current code and what my ide terminal thinks it sees when my internet is glitchy.
I had originally used a where just to get an idea if it was working properly (to show myself that it was only going to return one valid record). Then I modified it to be find_by (what I actually wanted), but it kept on returning results as if the where was still there. Then, bingo, it started to behave as expected. ???
My only explanation is these intermittent outages are affecting the internet connection to my ide.
So in rails we could find a record by name, id etc, similarly i want to do in ember without making a server request
I have a model called person{id, name}. If i want to peek a record by id i do this:
this.get('store').peekRecord('person', id)
which gives me the record based on id, but now i want to peek a record with a particular name, i tried something like this:
this.get('store').peekRecord('person', {name: "testname"})
which dose not seem to work.
i need a way peek a record using just the name
You can only peekRecord using the unique identifier for the model, which is id property. If you do want to make a request then queryRecord is what you want. but you don't want to make a request so the only choice is peekAll and filter the result,
let allRecord = this.get('store').peekAll('person');
let filteredResult = allRecord.filterBy('name','testname');
//filteredResult is an array of matching records
I have created a PI, :P1_ID defined as checkbox and added a DA to update a field on specific criteria.
On form, have a :P1_REF_NAME which contain the emailAdd of user who has login
e.g app_user = TESTUSER
:P1_REF_NAME = TESTUSER#TESTING.COM
I want to do something like that the checkbox option should be hidden / disable when User who login access his own record.
Any idea, How is it possible to do that pls?
If P1_REF_NAME contains the username then you could put a Condition on the item of type PL/SQL with expression
:P1_REF_NAME != :APP_USER
Then the item will not be rendered for the user's own record.
However, in your case it seems that the item contains a different value, i.e. the email address associated with the user. Presumably this is held in some table. In that case you can use a condition of type "SQL Not Exists" with an expression something like:
select null
from my_user_table
where username = :APP_USER
and email_address = :P1_REF_NAME
For each User I want to display his invitation status:
"Invitation Sent" or "Invitation Accepted"
Currently I just check if a field encrypted_password in Users table contains anything.
If it is not - then a user did not registered (accepted an invitation) yet but it was sent to him (otherwise this user's record would not exist in DB)
Is there a more elegant way to do it?
Yes you should take a
is_registered:boolean
column in user table which contains default value "false". Now you just have to do is when user get registered that time you just change value to "true".
when ever you want to check is user registered? just do
#user.is_registered? or current_user.is_registered?
this returns true/false
How to verify email through link.
I have user edit profile and it is showing user email.I want to give one link to verify email.I do not what to do.
Add one column to your
User Model : email_verification and by default set to zero (0).
Then using persistence_token create a URL and sent to that specific email address. If you dnt have persistence_token as column in your User model then you can add custom column of your choice like verify_email_token as column name and stored 50 random string.
Using
o = [('a'..'z'),('A'..'Z'),('0'..'9')].map{|i| i.to_a}.flatten
string = (0...50).map{ o[rand(o.length)] }.join
URL example :
http://www.yoursitename.com/VerifyEmailAddress/?token=persistence_token ;
When user click on that link, internally call function like VerifyEmailAddress and in that method update email_verification column by one (1).